当前位置:网站首页>Event center parameter transfer, peer component value transfer method, brother component value transfer
Event center parameter transfer, peer component value transfer method, brother component value transfer
2022-07-06 20:17:00 【imkaifan】
Parent component :
<template>
<div class="home">
<tom />
<jerray />
</div>
</template>
<script>
// @ is an alias to /src
import Tom from '@/components/eventbus/tom.vue'
import Jerray from '@/components/eventbus/jerray.vue'
export default {
name: 'Home',
components: {
Tom,
Jerray
}
}
</script>
Two sub components at the same level
Catalog :
Event center :
tom:
<template>
<div>
<div>Tom</div>
<div>{
{
num}}</div>
<button @click="handle"> Click on </button>
</div>
</template>
<script>
import eventBus from './eventbus'
export default {
name: 'Tom',
components: {
},
props: {
},
data () {
return {
num: 0,
dataTom: 11111
}
},
watch: {
},
computed: {
},
methods: {
handle () {
eventBus.$emit('jerray-event', this.dataTom)
}
},
created () {
},
mounted () {
// Monitoring events
eventBus.$on('tom-event', (val) => {
this.num = val
})
}
}
</script>
<style lang="less" scoped>
</style>
jerray:
<template>
<div>
<div>jerray</div>
<div>{
{
num}}</div>
<button @click="handle"> Click on </button>
</div>
</template>
<script>
import eventBus from './eventbus'
export default {
name: 'Jerray',
components: {
},
props: {
},
data () {
return {
num: 0,
dataJerray: 222222
}
},
watch: {
},
computed: {
},
methods: {
handle () {
eventBus.$emit('tom-event', this.dataJerray)
}
},
created () {
},
mounted () {
// Monitoring events
eventBus.$on('jerray-event', (val) => {
this.num = val
})
}
}
</script>
<style lang="less" scoped>
</style>
Mechanism thinking
use vue Instance as the event center : In fact, I don't understand this , But it must be useful , oh , He's meow , When I went to get a glass of water, I thought a little , Why? , Because we need to use it $emit To trigger the event , Who has $emit, It must be vue Examples
eventBus.$on Is to add an event to the event center , And then the operation triggered by the event , Be similar to addEventListener usage .
And then use $emit To trigger this event . This is actually very clever , This $emit , How to use it like this , It can also be in parent-child components , What about the method that the child component triggers the parent component ?
边栏推荐
- 报错分析~csdn反弹shell报错
- beegfs高可用模式探讨
- 永磁同步电机转子位置估算专题 —— 基波模型与转子位置角
- Unity making plug-ins
- 02 basic introduction - data package expansion
- RT-Thread 组件 FinSH 使用时遇到的问题
- Selenium advanced operations
- Initial experience of addresssanitizer Technology
- 腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
- Tencent architects first, 2022 Android interview written examination summary
猜你喜欢
5. Wireless in vivo nano network: top ten "feasible?" problem
Le lancement du jupyter ne répond pas après l'installation d'Anaconda
beegfs高可用模式探讨
22-07-05 七牛云存储图片、用户头像上传
棋盘左上角到右下角方案数(2)
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
2022年6月语音合成(TTS)和语音识别(ASR)论文月报
Monthly report of speech synthesis (TTS) and speech recognition (ASR) papers in June 2022
【云原生与5G】微服务加持5G核心网
Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model
随机推荐
PowerPivot - DAX (first time)
Notes on beagleboneblack
使用ssh连接被拒
AsyncHandler
String length limit?
Linear distance between two points of cesium
Cesium Click to draw a circle (dynamically draw a circle)
持续测试(CT)实战经验分享
01 基础入门-概念名词
Is it difficult for small and micro enterprises to make accounts? Smart accounting gadget quick to use
Tencent cloud database public cloud market ranks top 2!
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
beegfs高可用模式探讨
New generation garbage collector ZGC
Special topic of rotor position estimation of permanent magnet synchronous motor -- Summary of position estimation of fundamental wave model
Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,
Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
新一代垃圾回收器—ZGC
01 basic introduction - concept nouns
腾讯架构师首发,2022Android面试笔试总结