当前位置:网站首页>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. 无线体内纳米网:十大“可行吗?”问题
- Period compression filter
- Appx code signing Guide
- Anaconda安装后Jupyter launch 没反应&网页打开运行没执行
- What happened to the kernel after malloc() was transferred? Attached malloc () and free () implementation source
- Oceanbase Community Edition OBD mode deployment mode stand-alone installation
- 腾讯云数据库公有云市场稳居TOP 2!
- String长度限制?
- Monthly report of speech synthesis (TTS) and speech recognition (ASR) papers in June 2022
- PHP与EXCEL PHPExcel
猜你喜欢
Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development
夏志刚介绍
BUUCTF---Reverse---easyre
B-杰哥的树(状压树形dp)
5. 无线体内纳米网:十大“可行吗?”问题
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
Cesium 点击绘制圆形(动态绘制圆形)
Redisson bug analysis
【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN
Introduction of Xia Zhigang
随机推荐
Database specific interpretation of paradigm
22-07-05 七牛云存储图片、用户头像上传
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
Selenium advanced operations
【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
【计网】第三章 数据链路层(3)信道划分介质访问控制
SQL injection 2
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Special topic of rotor position estimation of permanent magnet synchronous motor -- Summary of position estimation of fundamental wave model
RT thread I2C tutorial
5. 无线体内纳米网:十大“可行吗?”问题
Tencent T3 Daniel will teach you hand-in-hand, the internal information of the factory
夏志刚介绍
8086 instruction code summary (table)
永磁同步电机转子位置估算专题 —— 基波模型类位置估算概要
Enumeration gets values based on parameters
Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
[Yann Lecun likes the red stone neural network made by minecraft]
Maximum likelihood estimation and cross entropy loss
腾讯架构师首发,2022Android面试笔试总结