.sync语法糖 子组件内修改父组件的值

155 阅读1分钟

.sync语法糖 子组件内修改父组件的值

父组件:

<son :fromFather.sync="fromSon"></son>
data(){
  return{
     fromSon:"父组件的值"
   }
},

子组件:

//props
props: {
  fromFather: {
    type: String,
    default: ''
  },
},
//页面
<el-button @click="change">改变他</el-button>
<div>{{fromFather}}</div>

//按钮的change事件来改变fromFather的值
change() {
	this.$emit('update:fromFather',"我可以改变了!!")
}