<li>
<div>
<label>验证码</label>
<input type="text" v-bind:class="{ error: hasError.code }"
@blur="codeBlur" v-model='code' placeholder="请输入验证码">
<a href="javascript:;" @click.prevent='sendCode'>{{ codeText }}</a>
<p class="error">{{ errorText.code }}</p>
</div>
</li>
sendCode: function() {
let that = this;
if (this.mailBlur()) {
// 改为邮箱验证码
ajax.post('/api/public/sendCode', { email: this.mail }, function(response) {
if (response.code != -1) {
that.realCode = response.data.code;
that.resetMailTime();
} else {
alert(response.msg)
}
}, "json");
}
},
resetMailTime: function(e) {
let num = 5,
that = this;
that.codeText = num + "秒后重新发送";
let time = setInterval(function() {
num--;
that.codeText = num + "秒后重新发送";
if (num == 0) {
clearInterval(time);
time = null;
that.codeText = "重发验证码";
}
}, 1000);
},

.prevent - 调用 event.preventDefault()
即取消事件的默认动作。a
标签href
不加javascript:;
也是不会刷新页面的。