当前位置:网站首页>Value transfer communication between components (parent to child, child to parent, brother component to value)
Value transfer communication between components (parent to child, child to parent, brother component to value)
2022-07-04 03:33:00 【CC ° fade】
List of articles
Preface
There are three kinds of value transmission communication between components
1、 Father's son
2、 Son father
3、 Sibling components pass values
One 、 Father's son
Parent component :<son :msg=“fatherMsg”></son>
Child components :props:[‘msg’]
// Parent component
<template>
<div>
<son :msg="fatherMsg"></son>
</div>
</template>
<script> import son from './son' export default {
data(){
return {
fatherMsg:' Parent component msg', } }, components:{
son } } </script>
// Child components
<template>
<div>
Messages received by subcomponents :{
{msg}}
</div>
</template>
<script> export default {
props:['msg'], } </script>
Two 、 Son father
Parent component :
<son @ Custom event name =“ Method ”></son>
Child components :
props:[‘ Custom event name ’]
this.$emit( Custom event name , Data to be transmitted )
// Parent component
<template>
<div>
<son @send="send"></son>
</div>
</template>
<script> import son from './son' export default {
components:{
son }, methods:{
send(msg){
console.log(' Message received by parent component :'+msg) }, }, } </script>
// Child components
<template>
<div>
<button @click="toFather"> Send to parent </button>
</div>
</template>
<script> export default {
props:['send'], methods:{
toFather(){
this.$emit('send',' Subcomponents msg') } }, } </script>
3、 ... and 、 Sibling components pass values
Through a transit (bus):
import Vue from ‘vue’
export default new Vue;
A Brother's biography :
import bus from ‘@/common/bus.js’
bus.$emit(‘toBorther’,this.msg)
B Brothers receive :
import bus from ‘@/common/bus.js’
bus.$on(‘toBorther’,(data)=>{
this.msg=data
})
// Parent component
<template>
<div class="about">
<!-- Sibling components pass values -->
<sister></sister>
<brother></brother>
</div>
</template>
<script> import sister from '../components/sister' import brother from '../components/brother' export default {
data(){
return{
} }, components:{
sister, brother }, } </script>
// transit (bus.js)
import Vue from 'vue'
export default new Vue;
//A Components (sister.vue)
<template>
<div>
<button @click="send"> push parameter </button>
</div>
</template>
<script> import bus from '@/common/bus.js' export default {
data(){
return{
msg:" This is a A The data of " } }, methods:{
send(){
// push parameter bus.$emit('toBorther',this.msg) } }, } </script>
//B Components (borther.vue)
<template>
<div>
{
{msg}}
</div>
</template>
<script> import bus from '@/common/bus.js' export default {
data(){
return{
msg:'', } }, mounted(){
bus.$on('toBorther',(data)=>{
// Receiving parameters this.msg=data }) }, } </script>
边栏推荐
- Which product is better for 2022 annual gold insurance?
- Recursive structure
- PID of sunflower classic
- Résumé des outils communs et des points techniques de l'examen PMP
- 7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
- [UE4] parse JSON string
- Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches
- 【.NET+MQTT】.NET6 環境下實現MQTT通信,以及服務端、客戶端的雙邊消息訂閱與發布的代碼演示
- The difference between MCU serial communication and parallel communication and the understanding of UART
- Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
猜你喜欢

7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
![Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]](/img/0d/7a8370d153a8479b706377c3487220.jpg)
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
![Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]](/img/ad/b675364fcaf5d874397fd0cbfec11b.jpg)
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]

The "message withdrawal" of a push message push, one click traceless message withdrawal makes the operation no longer difficult

Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?

Webhook triggers Jenkins for sonar detection

Unity controls the selection of the previous and next characters
![Backpropagation formula derivation [Li Hongyi deep learning version]](/img/ef/f76eae39c4f8716a0030a60c85b09c.gif)
Backpropagation formula derivation [Li Hongyi deep learning version]

@Scheduled scheduled tasks

Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
随机推荐
I stepped on a foundation pit today
Slurm view node configuration information
The property of judging odd or even numbers about XOR.
I stepped on a foundation pit today
JVM family -- heap analysis
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Have you entered the workplace since the first 00???
POSTECH | option compatible reward reverse reinforcement learning
What kind of experience is it when the Institute earns 20000 yuan a month!
In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c
MySQL data query optimization -- data structure of index
Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
logistic regression
Zlmediakit compilation and webrtc push-pull flow testing
Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to
WP collection plug-in free WordPress collection hang up plug-in