<input v-model='password' ref='password' /><script type="text/javascript">new Vue({ el:'.loginDiv', data:{ password:''
}, methods:{ submitForm:function() { var sha = hex_sha1(this.password); this.password = sha; console.log(this.$refs.password.value)
}
}
})</script>为什么我执行submitForm这个函数,改变password,而this.$refs.password.value打印出来的却不是password的值
1 回答

肥皂起泡泡
TA贡献1829条经验 获得超6个赞
password
值是同步更新的,而 DOM 是异步更新的。可以等本轮 DOM 更新再获取 DOM 值。
this.$nextTick(() => { console.log(this.$refs.password.value) })
添加回答
举报
0/150
提交
取消