使用下面的两个操作,可以等价于v-model
的双向绑定
:value
进行message
到input
的传参@input
进行input
到message
的传参
<body>
<div id="app">
<input type="text" :value="message" @input="changeValue">
<!-- <input type="text" v-model="message"> -->
<h2>{{message}}</h2>
</div>
<script type="text/javascript">
const app = new Vue({
el: '#app',
data: {
message: '你好,世界!'
},
methods: {
changeValue(event){
this.message = event.target.value;
}
}
})
</script>
</body>