国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

node.js|vue.js|jquery|angularjs|React|json|js教程|

服務器之家 - 編程語言 - JavaScript - 詳解vue中在父組件點擊按鈕觸發(fā)子組件的事件

詳解vue中在父組件點擊按鈕觸發(fā)子組件的事件

2021-11-17 16:30谷歌研發(fā)技術團隊 JavaScript

這篇文章主要介紹了詳解vue中在父組件點擊按鈕觸發(fā)子組件的事件,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

我把這個實例分為幾個步驟解讀:

1、父組件的button元素綁定click事件,該事件指向notify方法
2、給子組件注冊一個ref=“child”
3、父組件的notify的方法在處理時,使用了$refs.child把事件傳遞給子組件的parentMsg方法,同時攜帶著父組件中的參數msg
 4、子組件接收到父組件的事件后,調用了parentMsg方法,把接收到的msg放到message數組中

父組件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<template>
 <div id="app">
  <!--父組件-->
  <input v-model="msg" />
  <button v-on:click="notify">廣播事件</button>
  <!--子組件-->
  <popup ref="child"></popup>
 </div>
</template>
 <script>
import popup from "@/components/popup";
export default {
 name: "app",
 data: function () {
  return {
   msg: "",
  };
 },
 components: {
  popup,
 },
 methods: {
  notify: function () {
   if (this.msg.trim()) {
    this.$refs.child.parentMsg(this.msg);
   }
  },
 },
};
</script>
 <style>
#app {
 font-family: "Avenir", Helvetica, Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
}
</style>

子組件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<template>
 <div>
  <ul>
   <li v-for="item in messages">父組件輸入了:{{ item }}</li>
  </ul>
 </div>
</template>
 <style>
body {
 background-color: #ffffff;
}
</style>
 <script>
export default {
 name: "popup",
 data: function () {
  return {
   messages: [],
  };
 },
 methods: {
  parentMsg: function (msg) {
   this.messages.push(msg);
  },
 },
};
</script>

到此這篇關于詳解vue中在父組件點擊按鈕觸發(fā)子組件的事件的文章就介紹到這了,更多相關vue 父組件觸發(fā)子組件內容請搜索服務器之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/ZiChen_Jiang/article/details/109266736

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: www国产亚洲精品久久网站 | 国产欧美日韩在线 | 国产美女啪啪 | 久久美 | 好看毛片| 久草成人 | 中文天堂在线观看视频 | 日韩在线中文字幕 | 日韩在线一区二区三区 | 黄色一级视频 | 午夜国产 | 亚洲精品国产a | 97在线观看视频 | 欧美日韩在线免费 | www国产亚洲精品久久网站 | 玖玖综合网 | 蜜桃国精产品二三三区视频 | 99热婷婷 | 午夜久久久 | 欧美狠狠 | 精品一区二区三区在线观看 | 欧美成人精品一区二区三区 | 伊人伊人| 不卡的一区二区 | 欧美 日韩 中文字幕 | 中文字幕高清视频 | 久久久www成人免费无遮挡大片 | 亚洲免费美女视频 | 99在线精品视频 | 高清一区二区三区 | 日韩五月| 欧美精品在线一区 | 日韩一区二区三区在线看 | 国产精彩视频 | 日韩视频精品在线 | 91精品国产欧美一区二区成人 | 日韩精品三区 | 国产丝袜视频 | 久久视频在线看 | 久久天天 | 欧美黄视频在线观看 |