久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

vue中父子組件的參數傳遞和應用示例

瀏覽:4日期:2022-10-12 17:11:54
1.在父組件中調用子組件,父親傳值給子組件

子組件如下,把要傳給給父親的值放在props中

template> <!--底部導航--> <div class='index-bbar'> <ul > <li v-for='(item,index) in liAry' :class='index==licurrent?’active’:’’'> <router-link :to='item.linkURl'><span class='flex alignc flexdc'> <img :src='http://m.baoyu77737.com/bcjs/index==licurrent?require(’../../’ + item.urlActive):require(’../../’ + item.url)' ><span>{{item.title}}</span></span> </router-link> </li> </ul> </div></template><script>export default { name: ’Bottom’, data () { return { } }, props:[’liAry’,’licurrent’], methods: { }}</script><style scoped>@import '../../assets/public/css/top.css';@import '../../assets/public/css/bottom.css';</style>

父組件的調用的三部曲

首先引入子組件

import Bottom from ’@/components/public/Bottom’;

注入組件在components中注入

components: {Bottom}

在父親中應用

<template><Bottom v-bind:liAry=’lidata’ v-bind:licurrent=’guidecurrent’></Bottom></template>

到這里就結束了,是不是賊快

2.子組件傳值給父組件

父組件在組件上定義了一個自定義事件childFn,事件名為parentFn用于接受子組件傳過來的message值。

<!-- 父組件 --><template> <div class='test'> <test-com @childFn='parentFn'></test-com> <br/> 子組件傳來的值 : {{message}} </div></template><script>export default { // ... data: { message: ’’ }, methods: { parentFn(payload) { this.message = payload; } }}</script>

子組件是一個buttton按鈕,并為其添加了一個click事件,當點擊的時候使用$emit()觸發事件,把message傳給父組件

<!-- 子組件 --><template> <div class='testCom'> <input type='text' v-model='message' /> <button @click='click'>Send</button></div></template><script>export default { // ... data() { return { // 默認 message: ’我是來自子組件的消息’ } }, methods: { click() { this.$emit(’childFn’, this.message); } } }</script>

在子組件向父親傳值的時候,不可用router-link,不然接受不到父親定義的函數

以上就是vue中父子組件的參數傳遞和應用示例的詳細內容,更多關于vue中父子組件的參數傳遞的資料請關注好吧啦網其它相關文章!

標簽: Vue
相關文章:
主站蜘蛛池模板: 四川省| 柏乡县| 东明县| 恭城| 永新县| 象山县| 小金县| 当雄县| 疏勒县| 临安市| 绿春县| 隆昌县| 明光市| 长泰县| 旅游| 丁青县| 封丘县| 嘉兴市| 宝兴县| 陵川县| 安顺市| 东方市| 开原市| 彭阳县| 上蔡县| 环江| 新绛县| 利川市| 白河县| 额济纳旗| 建湖县| 青神县| 平塘县| 错那县| 泾阳县| 靖边县| 隆德县| 万载县| 镶黄旗| 鲜城| 兴海县|