当前位置:网站首页>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>
边栏推荐
- Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
- 7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
- Recent learning fragmentation (14)
- JVM family -- heap analysis
- Code Execution Vulnerability - no alphanumeric rce create_ function()
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验6 独立看门狗实验(学习笔记)
- false sharing
- Leetcode 110 balanced binary tree
- Redis transaction
- Lichuang EDA learning notes 14: PCB board canvas settings
猜你喜欢

I stepped on a foundation pit today

No clue about the data analysis report? After reading this introduction of smartbi, you will understand!

Rhcsa day 3

Why is it recommended that technologists write blogs?

Monitoring - Prometheus introduction

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

(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)

Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex

96% of the collected traffic is prevented by bubble mart of cloud hosting

Lichuang EDA learning notes 14: PCB board canvas settings
随机推荐
What is cloud primordial?
Why is it recommended that technologists write blogs?
Eh, the log time of MySQL server is less than 8h?
WP collection plug-in free WordPress collection hang up plug-in
Slurm view node configuration information
Future源碼一觀-JUC系列
[untitled]
JVM family -- heap analysis
warning: LF will be replaced by CRLF in XXXXXX
Record a problem that soft deletion fails due to warehouse level error
Want to do something in production? Then try these redis commands
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
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
How to use websocket to realize simple chat function in C #
Rhcsa day 2
Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
How to pipe several commands in Go?
150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches
基於.NetCore開發博客項目 StarBlog - (14) 實現主題切換功能