When we use components, we may need to bind the value of the subcomponent to the parent component.
The parent component passes parameters to the child component through v-model
<myEditor
class="m-top-10"
:key="editorForm"
v-model="visitRecordInfo.visit_comment"
/>
The subcomponent gets the passed parameters through props modelValue
props: {
modelValue: {
type: String,
default: () => {
return "";
},
},
}, // 接收传过来的数据
setup(props, context) {
// 赋值
const valueHtml = ref(props.modelValue);
// 监听子组件数据变动 修改父级 modelValue
watch(valueHtml,(newValue,oldValue)=>{
// newValue 新值, oldValue 旧值
context.emit('update:modelValue', newValue)
})
}