如何详细解析VUE中子组件向父组件传递多个值及额外信息的方法?
- 内容介绍
- 文章标签
- 相关推荐
本文共计680个文字,预计阅读时间需要3分钟。
一、子组件向父组件传递一个值子组件:javascriptthis.$emit('change', this.value);
父组件:javascript!-- 在父组件中使用子组件 --!
一、子组件向父组件传递一个值
子组件:
this.$emit('change', this.value);
父组件:
<!-- 在父组件中使用子组件 --> <editable-cell :text="text" :inputType="inputType" @change="costPlannedAmountChange($event)" />
// 事件处理函数 async costPlannedAmountChange(value) { console.log(value) }
在使用子组件时,绑定change函数的事件处理函数也可以写成如下格式:
<editable-cell :text="text" :inputType="inputType" @change="costPlannedAmountChange" />
绑定事件处理函数时,可以不带括号,形参则默认为事件对象,如果绑定时带上了括号,再想使用事件对象则需要传入$event作为实参。
二、子组件向父组件传递一个值,并携带额外参数
record为额外参数( 本文的额外参数都拿record做举例 )。
本文共计680个文字,预计阅读时间需要3分钟。
一、子组件向父组件传递一个值子组件:javascriptthis.$emit('change', this.value);
父组件:javascript!-- 在父组件中使用子组件 --!
一、子组件向父组件传递一个值
子组件:
this.$emit('change', this.value);
父组件:
<!-- 在父组件中使用子组件 --> <editable-cell :text="text" :inputType="inputType" @change="costPlannedAmountChange($event)" />
// 事件处理函数 async costPlannedAmountChange(value) { console.log(value) }
在使用子组件时,绑定change函数的事件处理函数也可以写成如下格式:
<editable-cell :text="text" :inputType="inputType" @change="costPlannedAmountChange" />
绑定事件处理函数时,可以不带括号,形参则默认为事件对象,如果绑定时带上了括号,再想使用事件对象则需要传入$event作为实参。
二、子组件向父组件传递一个值,并携带额外参数
record为额外参数( 本文的额外参数都拿record做举例 )。

