当前位置:网站首页>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 ?
边栏推荐
- JVM_ Common [interview questions]
- rt-thread i2c 使用教程
- 【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
- 枚举根据参数获取值
- How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
- [network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
- Tencent cloud database public cloud market ranks top 2!
- SSH connection denied
- 2022年6月语音合成(TTS)和语音识别(ASR)论文月报
猜你喜欢
Digital triangle model acwing 1018 Minimum toll
Speech recognition (ASR) paper selection: talcs: an open source Mandarin English code switching corps and a speech
Anaconda安裝後Jupyter launch 沒反應&網頁打開運行沒執行
BeagleBoneBlack 上手记
Example of shutter text component
beegfs高可用模式探讨
【云原生与5G】微服务加持5G核心网
腾讯T4架构师,android面试基础
Node. Js: express + MySQL realizes registration, login and identity authentication
Crawler (14) - scrape redis distributed crawler (1) | detailed explanation
随机推荐
HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
Unity writes a timer tool to start timing from the whole point. The format is: 00:00:00
Poj3617 best cow line
Le lancement du jupyter ne répond pas après l'installation d'Anaconda
BUUCTF---Reverse---easyre
Anaconda安裝後Jupyter launch 沒反應&網頁打開運行沒執行
22-07-05 upload of qiniu cloud storage pictures and user avatars
Jupyter launch didn't respond after Anaconda was installed & the web page was opened and ran without execution
Selenium advanced operations
Initial experience of addresssanitizer Technology
某东短信登录复活 安装部署教程
How to handle the timeout of golang
Unity makes AB package
Logstash expressway entrance
Tencent byte Alibaba Xiaomi jd.com offer got a soft hand, and the teacher said it was great
Qinglong panel white screen one key repair
方法关键字Deprecated,ExternalProcName,Final,ForceGenerate
RT thread I2C tutorial
An East SMS login resurrection installation and deployment tutorial
系统与应用监控的思路和方法