直接上代碼吧:
<!-- 父組件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');
}
}
}
