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');
    }
  }
}

  

posted @ 2020-09-25 18:03  lsboom  阅读(5975)  评论(0编辑  收藏  举报