<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<input type="text" :value="title" @input="onInput">
<!-- <input :value="title" @input="title = $event.target.value"> --> // $event.target.value 就是把input的值赋值给 price
<div>
{{title}}
</div>
</div>
<script src="vue.js"></script>
<script>
const app = new Vue(
{
el:"#app",
data() {
return {
title:"hello vue"
}
},
methods:{
onInput(e) {
console.log(e);
this.title = e.target.value;
}
}
}
)
</script>
</body>
</html>
v-model其实相当于一个语法糖,这里不使用语法糖实现v-model的功能