最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue中$emit傳遞多個(gè)參(arguments和$event)

 更新時(shí)間:2023年02月02日 09:18:44   作者:清風(fēng)細(xì)雨_林木木  
本文主要介紹了vue中$emit傳遞多個(gè)參(arguments和$event),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

使用 $emit 從子組件傳遞數(shù)據(jù)到父組件時(shí),主要有以下3類情況

1.只有子組件傳值(單個(gè)、多個(gè))

寫法一:(自由式)

// child組件,在子組件中觸發(fā)事件
this.$emit('handleFather', '子參數(shù)1','子參數(shù)2','子參數(shù)3')
// father組件,在父組件中引用子組件
<child @handleFather="handleFather"></child>
<script>
export default {
   components: {
    child,
   }
   methods: {
     handleFather(param1,param2,param3) {
         console.log(param) // 
     }
   }
 }
 </script>

解析:

  • 只有子組件傳值;
  • 注意@引用函數(shù)不需要加“括號”;
  • 子組件傳值和父組件方法的參數(shù)一一對應(yīng)。

寫法二:(arguments寫法)

// child組件,在子組件中觸發(fā)事件并傳多個(gè)參數(shù)
this.$emit('handleFather', param1, param2,)
//father組件,在父組件中引用子組件
<child @handleFather="handleFather(arguments)"></child>
<script>
  export default {
    components: {
     child,
    }
    methods: {
      handleFather(param) {
          console.log(param[0]) //獲取param1的值
          console.log(param[1]) //獲取param2的值
      }
    }
  }
</script>

解析:

  • 只有子組件傳值;
  • 注意@引用函數(shù)添加“arguments”值;
  • 打印出子組件傳值的數(shù)組形式。

2.子組件傳值,父組件也傳值

寫法一:

// child組件,在子組件中觸發(fā)事件
this.$emit('handleFather', '子參數(shù)對象')
//father組件,在父組件中引用子組件
<child @handleFather="handleFather($event, fatherParam)"></child>
 
<script>
 export default {
   components: {
    child,
   }
   methods: {
     handleFather(childObj, fatherParam) {
         console.log(childObj) // 打印子組件參數(shù)(對象)
         console.log(fatherParam) // 父組件參數(shù)
     }
   }
 }
</script>

寫法二:

// child組件,在子組件中觸發(fā)事件并傳多個(gè)參數(shù)
this.$emit('handleFather', param1, param2,)
//father組件,在父組件中引用子組件
<child @handleFather="handleFather(arguments, fatherParam)"></child>

<script>
?export default {
? ?components: {
? ? child,
? ?}
? ?methods: {
? ? ?handleFather(childParam, fatherParam) {
? ? ? ? ?console.log(childParam) //獲取arguments數(shù)組參數(shù)
? ? ? ? ?console.log(fatherParam) //獲取fatherParam
? ? ?}
? ?}
?}
</script>

總結(jié):

  • 只有子組件傳參,@調(diào)用方法不使用“括號”
  • 特殊使用“arguments”和“$event”,
  • arguments 獲取子參數(shù)的數(shù)組
  • $event 獲取自定義對象,滿足傳多個(gè)參數(shù)

到此這篇關(guān)于vue中$emit傳遞多個(gè)參(arguments和$event)的文章就介紹到這了,更多相關(guān)vue $emit傳遞多個(gè)參內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

最新評論

瑞丽市| 三河市| 玉田县| 平武县| 泽库县| 察隅县| 安康市| 邵阳市| 城步| 邵武市| 信宜市| 长汀县| 海兴县| 石棉县| 诏安县| 城步| 伊宁市| 普宁市| 安化县| 鹤峰县| 平远县| 建始县| 城步| 寻乌县| 景宁| 雅江县| 安溪县| 大新县| 霍州市| 登封市| 习水县| 南涧| 临海市| 武鸣县| 凤山市| 赫章县| 紫云| 鸡泽县| 合肥市| 衡东县| 七台河市|