国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

vue.js $refs和$emit 父子組件交互的方法

2024-05-06 15:23:25
字體:
供稿:網(wǎng)友

本文介紹了vue.js $refs和$emit 父子組件交互的方法,分享給大家,廢話不多說直接看代碼:

<strong>父調(diào)子 $refs (把父組件的數(shù)據(jù)傳給子組件) </strong><br><br><template> <div id="app">  <input type="button" name="" id="" @click="parentCall" value="父調(diào)子" />  <hello ref="chil" />//hello組件 </div></template><script> import hello from './components/Hello' export default {  name: 'app',  'components': {   hello  },  methods: {    parentCall () {      this.$refs.chil.chilFn('我是父元素傳過來的')    }  } }</script>/*Hello.vue :*/<template> <div class="hello"></div></template><script> export default {  name: 'hello',  'methods': {    chilFn (msg) {      alert(msg)    }  } }</script>
<strong>子調(diào)父 $emit (把子組件的數(shù)據(jù)傳給父組件)</strong>//ps:App.vue 父組件//Hello.vue 子組件<!--App.vue :--><template>  <div id="app">    <hello @newNodeEvent="parentLisen" />  </div></template><script> import hello from './components/Hello' export default {  name: 'app',  'components': {   hello  },  methods: {   parentLisen(evtValue) {     //evtValue 是子組件傳過來的值    alert(evtValue)   }  } }</script><!--Hello.vue :--><template>  <div class="hello">    <input type="button" name="" id="" @click="chilCall()" value="子調(diào)父" />   </div></template><script> export default {  name: 'hello',  'methods': {   chilCall(pars) {    this.$emit('newNodeEvent', '我是子元素傳過來的')   }  } }</script> 

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持錯(cuò)新站長站。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 黎川县| 南丹县| 宜昌市| 朔州市| 汝州市| 兴化市| 昂仁县| 甘肃省| 凉山| 秦皇岛市| 武川县| 乌拉特后旗| 曲水县| 新泰市| 广南县| 沙雅县| 准格尔旗| 靖边县| 淳化县| 横峰县| 木里| 汶上县| 克拉玛依市| 南投市| 岑溪市| 金昌市| 唐山市| 蒙阴县| 博罗县| 新郑市| 太康县| 乐业县| 剑川县| 浦县| 泗洪县| 当雄县| 牡丹江市| 迭部县| 长治市| 浮山县| 二连浩特市|