vue中$emit触发的事件传入自定义参数
直接上代码吧:
<!-- 父组件father -->
<template>
<child @click-fn="clickFn1('father', ...arguments)">在方法中传入额外参数(方法1)</child>
<child @click-fn="clickFn2('father')">在方法中传入额外参数(方法2)</child>
</template>
export default {
name: 'father',
methods: {
clickFn1(...arg) {
console.log(arg);
// 控制台输出['father', 'child']
},
clickFn2(arg1) {
return (arg2) => {
console.log([arg1, arg2]);
}
}
}
}
<!-- 子组件child -->
<template></template>
export default {
name: 'child',
methods: {
emitFn() {
this.$emit('click-fn', 'child');
}
}
}

浙公网安备 33010602011771号