Created
March 22, 2016 10:55
-
-
Save dreamkidd/ccb37aa7311e7aaa1f4d to your computer and use it in GitHub Desktop.
vue 自定义指令 点击后60秒静止点击
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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