$emit传递参数
$emit传递一个参数时//子组件代码let data = {name:'王五',age:'50'};this.$emit('change',data)//父组件代码<editable-cell @change="onCellChange($event)" />onCellChange(backMsg) {this.msg = backMsg;}$emit传递多个参数时//子组件代码l
·
$emit传递一个参数时
//子组件代码
let data = {name:'王五',age:'50'};
this.$emit('change',data)
//父组件代码
<editable-cell @change="onCellChange($event)" />
onCellChange(backMsg) {
this.msg = backMsg;
}
$emit传递多个参数时
//子组件代码
let data = {name:'王五',age:'50'};
let type = '5'
this.$emit('change',data,type)
//父组件代码如下
<editable-cell @change="onCellChange(arguments)" />
//arguments 是关键字
onCellChange(backMsg) {
this.data = backMsg[0]; //{name:'王五',age:'50'}
this.type = backMsg[1]; //5
}
通过$emit 实现子组件向父组件通信
更多推荐
已为社区贡献1条内容
所有评论(0)