Skip to content

Instantly share code, notes, and snippets.

@dreamkidd
Created March 22, 2016 10:55
Show Gist options
  • Save dreamkidd/ccb37aa7311e7aaa1f4d to your computer and use it in GitHub Desktop.
Save dreamkidd/ccb37aa7311e7aaa1f4d to your computer and use it in GitHub Desktop.
vue 自定义指令 点击后60秒静止点击
Vue.directive('cutdowntime', {
currentTime: 60,
isValidated: false,
bind: function () {
var self = this;
//self.vm;
//console.log(self.vm.$sign_phone_validation.phone.valid);
self.el.addEventListener('click', function (e) {
//if (self.vm.$sign_phone_validation.phone.valid) {
var interval = window.setInterval(function () {
if (self.currentTime == 0) {
$(self.el).removeClass('disabled');
$(self.el).text("获取短信验证码");
window.clearInterval(interval);
self.currentTime = 60;
} else {
self.currentTime--;
$(self.el).addClass("disabled");
$(self.el).text("请" + self.currentTime + "秒后重试");
}
}, 1000);
e.stopPropagation();
e.preventDefault();
return false;
}
);
//}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment