No trigger event, vue subassemblies pass values to the parent component

vue child pass the Father, it was originally thought to be triggered by an event, in order to pass a value to the parent component.

The results of the original can not. Others say vuex, too much trouble.

In fact, you can not. Then take a look at how to pass it.

 

Under the first scenario:

Subassembly created when some data on request to the data request to be passed to the parent component. At this point it has not trigger any event. Then to pass values ​​to the parent component, it is necessary to do so. (Actually, it's really simple)

Subcomponents Code:

xxx.then(res=>{
     this.childData = data.res
     this.$emit('cdata',this.childData)    // 刚求完直接$emit
})

Then, the receiving parent component should

import Child form 'xxx.vue'
<child @childData="getValue($event)"></child>

getValue(data){
  this.pdata = data
}

Such a request is complete, we can immediately get a parent component to child component data, do not trigger events

Guess you like

Origin www.cnblogs.com/luguankun/p/12501639.html