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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM