Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

vue 如何更优雅实现父子组件双向绑定?

我想封装一个公用的富文本子组件,父子组件传参使用props, $emit传参,子组件使用props接收参数content,在created 设置初始值,在watch监听父组件的改变的值content改变子组件的值valueData(比如请求接口后父组件传值渲染子组件),通过$emit 监听子组件富文本改变的同时修改父组件的值;
但是这样会导致子组件富文本每输入一个字都会触发 $emit 传到父组件,改变父组件的值,然后子组件又触发watch 修改一遍子组件的valueData,绕了一圈;
请教下有没有更优雅的方案(除了vuex)?

子组件VueEditor.vue
image.png

父组件
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

参考自定义v-model的用法


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...