<body>
<div id="app">
<!-- 在 组件上 使用 v-model
如果 input 属性 是 text 或者 textarea 元素
组件中 props 必须是 value
emit 事件名 必须是 input
-->
<my-input v-model="user"></my-input>
<my-input v-model="age"></my-input>
{{ user }} --- {{ age}}
</div>
<script>
Vue.component("MyInput",{
props:['value'],
template:`
<input type="text" :value="value" @input="fn($event)">
`,
methods: {
fn(e){
// console.log(e.target.value)
this.$emit("input",e.target.value)
}
},
})
new Vue({
el:"#app",
data:{
user:"gao" ,
age:19
}
})
</script>