当前位置:网站首页>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 ?
边栏推荐
- 5. 无线体内纳米网:十大“可行吗?”问题
- Zoom with unity mouse wheel: zoom the camera closer or farther
- PHP与EXCEL PHPExcel
- Enumeration gets values based on parameters
- RT-Thread 组件 FinSH 使用时遇到的问题
- Appx code signing Guide
- HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
- Digital triangle model acwing 1018 Minimum toll
- Cesium 两点之间的直线距离
- What happened to the kernel after malloc() was transferred? Attached malloc () and free () implementation source
猜你喜欢

永磁同步电机转子位置估算专题 —— 基波模型与转子位置角

Speech recognition (ASR) paper selection: talcs: an open source Mandarin English code switching corps and a speech

HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
腾讯架构师首发,2022Android面试笔试总结

PowerPivot - DAX (first time)

深度学习分类网络 -- ZFNet
Tencent architects first, 2022 Android interview written examination summary

棋盘左上角到右下角方案数(2)

beegfs高可用模式探讨
![[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN](/img/b8/3d48e185bb6eafcdd49889f0a90657.png)
[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
随机推荐
22-07-05 upload of qiniu cloud storage pictures and user avatars
String length limit?
Example of shutter text component
方法关键字Deprecated,ExternalProcName,Final,ForceGenerate
Unity load AB package
POJ 3207 Ikki&#39; s Story IV – Panda&#39; s Trick (2-SAT)
RT thread I2C tutorial
Database specific interpretation of paradigm
mod_wsgi + pymssql通路SQL Server座
AsyncHandler
Synchronization of data create trigger synchronization table for each site
Web security - payload
【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN
Extraction rules and test objectives of performance test points
永磁同步电机转子位置估算专题 —— 基波模型与转子位置角
Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
Leetcode question 448 Find all missing numbers in the array
JVM_常见【面试题】
使用ssh连接被拒
How to handle the timeout of golang