本篇文章為大家展示了使用vue怎么在子組件中調(diào)用兄弟組件,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括烏拉特后網(wǎng)站建設(shè)、烏拉特后網(wǎng)站制作、烏拉特后網(wǎng)頁制作以及烏拉特后網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,烏拉特后網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到烏拉特后省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
父組件示例代碼:
組件功能解析:
通過$emit獲取子組件事件,通過$ref調(diào)用子組件中事件,實(shí)現(xiàn)子組件二的click事件
調(diào)用兄弟組件一中的事件
<template>
<div>
<!-- 子組件1 -->
<son1 ref="borther" :dataFromFather="dataFromFather"></son1>
<!-- 子組件2 -->
<son2 @triggerBrotherMethods="triggerBrotherMethods" :dataFromFather="dataFromFather"></son2>
</div>
</template>
<script>
// 引入子組件一
import son1 from './son1'
// 引入子組件二
import son2 from './son2'
export default {
data() {
return {
dataFromFather: []
}
},
// 注冊子組件
components: {
son1,
son2
},
methods: {
// 子組件2中click事件
triggerBrotherMethods() {
// 父組件通過$ref調(diào)用子組件1中的事件方法
this.$refs.borther[0].bortherMethods()
},
}
}
</script>
<style lang="less" scoped>
/* .... */
</style>子組件一
組件功能解析:
加載父組件數(shù)據(jù),進(jìn)行業(yè)務(wù)操作
<template>
<!-- 子組件son2 -->
<div @click="bortherMethods">
<!-- 父組件傳值展示 -->
{{dataFromFather}}
</div>
</template>
<script>
export default {
data() {
return {
}
},
props: ['dataFromFather'],
methods: {
// 兄弟組件中的按鈕事件
bortherMethods() {
// 子組件事件方法
...
},
}
}
</script>
<style lang="less" scoped>
/* .... */
</style>子組件二:
組件功能解析:
加載父組件數(shù)據(jù),通過click事件emit傳給父組件
<template>
<!-- 子組件son2 -->
<div @click="triggerBrotherMethods">
<!-- 父組件傳值展示 -->
{{dataFromFather}}
</div>
</template>
<script>
export default {
data() {
return {
}
},
props: ['dataFromFather'],
methods: {
// 觸發(fā)兄弟組件中的按鈕事件
triggerBrotherMethods() {
this.$emit('clickBrotherBtn', true)
},
}
}
</script>
<style lang="less" scoped>
/* .... */
</style>上述內(nèi)容就是使用vue怎么在子組件中調(diào)用兄弟組件,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站標(biāo)題:使用vue怎么在子組件中調(diào)用兄弟組件
轉(zhuǎn)載注明:http://chinadenli.net/article14/ghooge.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)站改版、動態(tài)網(wǎng)站、品牌網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)