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

首頁 > 語言 > JavaScript > 正文

VUEJS 2.0 子組件訪問/調用父組件的實例

2024-05-06 15:21:55
字體:
來源:轉載
供稿:網友

有時候因為布局問題,需要子組件 把數據 傳給父組件,并執行父級的某個方法,不多說上代碼:

子組件:

<template>  <div class="isShowing" ref="isShowing">  <div class="menu-wrapper" ref="scroll_warpper" v-show="!hid_show_switch">   <ul ref="scroll_warpper_ul">   <li class="menu-item" @click="goToFatherDetail(233)">      </li>   </ul>  </div>  <v-loading class="isloading" v-show="hid_show_switch"></v-loading>  </div> </template>  <script type="text/ecmascript-6">   export default {  methods: {   goToFatherDetail (itemId) {   // this.$parent.$router.push('goToDetail');   console.log('子組件方法走了' + itemId);   this.$emit('refreshbizlines', itemId); /* <span style="font-family: Arial, Helvetica, sans-serif;">itemId就是子要傳的數據 - 這里很重要,refreshbizlines就是父組件$on監測的自定義函數不是父組件的自定義函數。*/</span>    }  }  }; </script> 

父組件:

<template>  <div class="main-wrapper">   <div class="tab-wrapper">   <div class="tab-item">    <router-link to="/isShowing" class="table-item-text">正在熱映</router-link>   </div>   <div class="tab-item">    <router-link to="/willShow" class="table-item-text">即將上映</router-link>   </div>   </div>  </div>  <router-view class="items-show" v-on:refreshbizlines="goToDetail" keep-alive></router-view>  </div> </template>  <script type="text/ecmascript-6">   export default {  methods: {   goToDetail (itemId) {   console.log('父組件走你:' + itemId);   }  }<strong>  }; </script></strong> 

父組件用 v-on 來做個監測的函數來檢測,最終生成的代碼是 類似

on: {  "refreshbizlines": function($event) {  _vm.goToDetail(123)}}

所以原理就是 子組件 訪問 父組件的 檢測函數 refreshbizlines ,訪問了,則執行 refreshbizline 下面的 函數

goToDetail -- 也就是父組件的

goToDetail函數

注意 父組件 的

v-on:refreshbizlines="goToDetail"

一定要放在 你父組件調用子組件的 模塊名上。

祝你們 編碼愉快。

以上這篇VUEJS 2.0 子組件訪問/調用父組件的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 中江县| 关岭| 乡宁县| 丹阳市| 鹿泉市| 镇坪县| 平南县| 望谟县| 永仁县| 紫金县| 唐河县| 阜城县| 京山县| 丹阳市| 新乡市| 洛川县| 高密市| 镇安县| 梁河县| 上思县| 文昌市| 监利县| 望江县| 安义县| 玛曲县| 白银市| 大港区| 曲松县| 治县。| 平和县| 新源县| 桃江县| 赣榆县| 伊通| 定安县| 修文县| 沿河| 区。| 沙洋县| 周宁县| 阳城县|