自定义v-model
文章目录
v-model是vue实现数据双向绑定最好的一个指令, v-model本质上不过是语法糖,它负责监听用户的输入事件以更新数据,当你修改页面的时候 v-model 自动去更新数据层 (model),当你修改数据的时候v-model自动去更新视图层 (view)
app.vue
<input type="text" :value="message" @input="changeAction"/>
data(){
return {
message: 'hello v-model',
}
},
methods: {
changeAction(ev){
console.log(ev.target.value);
//通过动态绑定value值,将input事件输入的值传入
this.message = ev.target.value;
},
}
下面的这个代码可以把v-model理解为 :value @input的合体
<input type="text" :value="message" @input="changeAction"/>
ok了

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论