当前位置:网站首页>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>
边栏推荐
- How much does it cost to open a futures account in China? Where is it safe to open an account at present?
- Day05 錶格
- Jenkins configures IP address access
- How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
- Handler source code analysis
- Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
- Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches
- New year's first race, submit bug reward more!
- Rhcsa day 3
- Explain AI accelerator in detail: why is this the golden age of AI accelerator?
猜你喜欢

How to use websocket to realize simple chat function in C #

Management and thesis of job management system based on SSM

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

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?

Package details_ Four access control characters_ Two details of protected

I stepped on a foundation pit today

JVM family -- heap analysis

Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!

7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
![[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush](/img/98/3e5f1094141e34d7e77f908e12acda.jpg)
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
随机推荐
PID of sunflower classic
Monitoring - Prometheus introduction
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
Why is it recommended that technologists write blogs?
Eh, the log time of MySQL server is less than 8h?
Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram
Solve the problems encountered by the laravel framework using mongodb
Session learning diary 1
Imperial cms7.5 imitation "D9 download station" software application download website source code
POSTECH | option compatible reward reverse reinforcement learning
I stepped on a foundation pit today
Consul of distributed service registration discovery and unified configuration management
MySQL backup notes
潘多拉 IOT 开发板学习(HAL 库)—— 实验6 独立看门狗实验(学习笔记)
super_ Subclass object memory structure_ Inheritance tree traceability
Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
PMP 考試常見工具與技術點總結
I stepped on a foundation pit today
Recent learning fragmentation (14)
logistic regression