vue里面的prevent怎么使用?还是使用别的事件修饰符?

<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);
    },

clipboard.png

阅读 10.5k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题