为什么change事件失去焦点没有作用?

这是子组件中:
<v-form-item class="pwd reg-cell" required :label="showlabel" prop="vertifyCode">

  <v-input v-model="vertifyCode" @change="send()" name="vertifyCode" placeholder="6位数字手机验证码"></v-input>
  <button type="button" class="uploadfile" id="getcode" @click="getcode">{{SMSCode}}</button>
</v-form-item>

methods:{

  //发送验证码
getcode(){
  this.intverTime = 10;
  var $up = $('#getcode');
  this.sentime =setInterval(() => {
    if ( this.intverTime > 0) {
      this.intverTime = this.intverTime -1;
      this.SMSCode = this.intverTime + "s 后重试";
      $up.attr("disabled",true);  
    } else {
      $up.attr("disabled",false);  
      this.SMSCode = "获取验证码";
      clearInterval(this.sentime);
      this.intverTime = 10;
      this.isloading = false;
    }
  }, 1000);
  post(this, api.sendCode, {'phoneNumber': this.phoneNumber }, (response) => {
    if (response.code == 0) {
      // callback();
      console.log('获取验证码成功');
    } else {
      this.SMSCode = "获取验证码";
      // clearInterval(this.sentime);
      this.intverTime = 10;
      this.isloading = false;
    }
  });
},
send(){
  console.log(this.vertifyCode);   //没有打印值,说明change事件没有触发,值发送不到父组件中去
  this.$emit('getVal',this.vertifyCode);
  // this.$emit('child-info',this.msgChild)
}

},

//父组件中
<v-getcode @getVal="phonecode" :phoneNumber="registerParams.phoneNumber" ></v-getcode>
methods: {

phonecode(val){
  console.log('接收子组件传过来的code值:'+val);
  this.registerParams.vertifyCode = val;
},

}

阅读 3k
3 个回答

失去焦点不会触发change事件吧,触发失焦的事件是@blur

change 只是在文本框发生变化是所触发的
你失去焦点 输入完成也可以用blur

但是这个不是特别如意

你直接watch 监听这个model值的变化不更好

触发change事件前提: 1、输入框中内容发生改变 2、失去焦点

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