Vue组件内部实现一个双向数据绑定的实例代码
思路:父组件通过props传值给子组件,子组件通过$emit来通知父组件修改相应的props值,具体实现如下:
importVuefrom'vue'
constcomponent={
props:['value'],
template:`
`,
data(){
return{}
},
methods:{
handleInput(e){
this.$emit('input',e.target.value)
}
}
}
newVue({
components:{
CompOne:component
},
el:'#root',
template:`
`,
data(){
return{
value:'123'
}
}
})
总结
以上所述是小编给大家介绍的Vue组件内部实现一个双向数据绑定的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!