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组件内部实现一个双向数据绑定的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短