:question.sync=”questionText”父子组件双向绑定
相当于:
:question = “questionText” @update:question = “(val)=> questionText = val ”
使用场景:
父组件数据查询数据库得到,子组件textarea写入数据,同步到父组件,然后在父组件中去保存数据
questionnaire.vue
<voice-question
:question.sync= “questionText”
>
</voice-question>
Voice-question.vue
props,watch
Props: {
question: {
type: String,
default: ‘’
}
}
watch: {
question(val){
this.$emit(‘update:question’,val);
}
}