Communication between vue components and components

there are two components in the

index page. There is an isCollapse value in data B A data. How can I get it in component B and do v-model

Aug.23,2021

1.vuex
2. Write a $bus bus communication, do not recommend


recommend vuex is better


A
:
html
<A :yourData="this.yourData"></A>
<script>
    import A from "";// 
    export default {
       components: { A },// 
       data(){
           return {
               yourData:''
           }
       }
    }
</script>

:
<input v-model="this.yourData"/>
<script>
    export default {
       props: ['yourData'],// 
       mounted(){
           console.log(this.yourData) // 
       }
    }
</script>

if the two elements have a common parent component, put the data and data changes to the parent component, bind the data to the child component through props, and all the changes are carried out in the parent component.
in other cases, it is really not possible to use eventBus.


two methods:
1.EventBus
2.Vuex (recommended)

Menu