当前位置:网站首页>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 ?
边栏推荐
- Database specific interpretation of paradigm
- POJ3617 Best Cow Line 馋
- 【GET-4】
- 语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech
- RT-Thread 组件 FinSH 使用时遇到的问题
- Example of applying fonts to flutter
- What happened to the kernel after malloc() was transferred? Attached malloc () and free () implementation source
- String length limit?
- Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00
- js获取浏览器系统语言
猜你喜欢

An East SMS login resurrection installation and deployment tutorial
腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发

Special topic of rotor position estimation of permanent magnet synchronous motor -- fundamental wave model and rotor position angle

HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅

Example of applying fonts to flutter

Continuous test (CT) practical experience sharing

5. 無線體內納米網:十大“可行嗎?”問題

BeagleBoneBlack 上手记

Maximum likelihood estimation and cross entropy loss

Configuration and simple usage of the EXE backdoor generation tool quasar
随机推荐
Anaconda安裝後Jupyter launch 沒反應&網頁打開運行沒執行
HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
SSH connection denied
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
logstash高速入口
Case ① | host security construction: best practice of 3 levels and 11 capabilities
Notes on beagleboneblack
Redisson bug analysis
B-jiege's tree (pressed tree DP)
Cesium 点击绘制圆形(动态绘制圆形)
Groovy basic syntax collation
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
2022年6月语音合成(TTS)和语音识别(ASR)论文月报
22-07-05 七牛云存储图片、用户头像上传
腾讯架构师首发,2022Android面试笔试总结
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
AsyncHandler
Selenium advanced operations
腾讯T4架构师,android面试基础
Initial experience of addresssanitizer Technology