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

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 14:41:17
字體:
來源:轉載
供稿:網友

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

<strong>父調子 $refs (把父組件的數據傳給子組件) </strong><br><br><template> <div id="app">  <input type="button" name="" id="" @click="parentCall" value="父調子" />  <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>子調父 $emit (把子組件的數據傳給父組件)</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="子調父" />   </div></template><script> export default {  name: 'hello',  'methods': {   chilCall(pars) {    this.$emit('newNodeEvent', '我是子元素傳過來的')   }  } }</script> 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙门县| 顺平县| 庆阳市| 卢龙县| 华宁县| 佛教| 峨边| 晋州市| 威信县| 南京市| 东乡| 苍溪县| 安福县| 墨脱县| 三门县| 南溪县| 房产| 台中县| 勃利县| 都昌县| 黄冈市| 永顺县| 上思县| 绥江县| 砀山县| 定州市| 西宁市| 全南县| 紫阳县| 永川市| 蒙阴县| 阿鲁科尔沁旗| 大城县| 龙里县| 呼玛县| 荆门市| 宁陵县| 永嘉县| 吉林市| 汾阳市| 平顺县|