当前位置:网站首页>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 ?
边栏推荐
- 【计网】第三章 数据链路层(3)信道划分介质访问控制
- 小微企业难做账?智能代账小工具快用起来
- JS get browser system language
- HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
- 永磁同步电机转子位置估算专题 —— 基波模型类位置估算概要
- Error analysis ~csdn rebound shell error
- 方法关键字Deprecated,ExternalProcName,Final,ForceGenerate
- 5. 无线体内纳米网:十大“可行吗?”问题
- Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
- 案例 ①|主机安全建设:3个层级,11大能力的最佳实践
猜你喜欢
SQL injection 2
某东短信登录复活 安装部署教程
Tencent Android development interview, basic knowledge of Android Development
持续测试(CT)实战经验分享
5. 无线体内纳米网:十大“可行吗?”问题
Special topic of rotor position estimation of permanent magnet synchronous motor -- fundamental wave model and rotor position angle
Example of applying fonts to flutter
腾讯架构师首发,2022Android面试笔试总结
Maximum likelihood estimation and cross entropy loss
Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
随机推荐
Cesium 点击绘制圆形(动态绘制圆形)
持续测试(CT)实战经验分享
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
01 basic introduction - concept nouns
某东短信登录复活 安装部署教程
Technology sharing | packet capturing analysis TCP protocol
腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
BeagleBoneBlack 上手记
RT-Thread 组件 FinSH 使用时遇到的问题
【云原生与5G】微服务加持5G核心网
Wechat applet common collection
Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00
夏志刚介绍
腾讯云数据库公有云市场稳居TOP 2!
Tencent T4 architect, Android interview Foundation
Groovy basic syntax collation
Tencent Android development interview, basic knowledge of Android Development
Catch ball game 1
Continuous test (CT) practical experience sharing
Leetcode question 283 Move zero