Brothers components by value

1, the sub-transmission Father, another sub transmission

。。。

2, vuex

 

3,eventBus

 Step 1: Create a js file, eventBus.js, just put the location, I was on the src directory

  Import view from 'View'
  export default new Vue () 

Step Two: In the outgoing assembly brothers values, introduced just js
  import '@ / eventBus.js' 

  and methods defined inside a function
  methods:{
      changesize(){
          eventBus.$emit('add',this.arg)
      }
  } 
  Test using a button click trigger changesize function, then arg spread out
the third step: the brothers accept the value of the component also let introduced eventBus.js, and then use the created life-cycle function
  created(){
      eventBus.$on('add',(message)=>{
          // Some operations, message is passed from brother components over value
          console.log(message)
      })
  },

Guess you like

Origin www.cnblogs.com/xudunwang/p/11871250.html