Vuejs 2.0 subcomponent Access / call the instance of the parent component

Sometimes, because of the layout problem, the subcomponents need to pass the data to the parent component, and perform a method of the parent, not to say the code:

Subcourse:

   
Export Default {Methods: {gotofatherDetail (itemid) {// this. $ PARENT. $ Router.push ('gotodetail'); console.log ('组 方法); this. $ EMIT ('refreshbizlines', itemid); / * ItemID is the data you want to pass - this is important, refreshbizlines is the custom function of the parent component $ ON is not a custom function of the parent component. * /
}}}; Parent component:

   is about to be released 
Export Default {Methods: {gotodetail (itemid) {Console.log('Parent component walks you:' + itemid);}} };
The parent component uses V-ON to do a monitoring The function is detected, the final generated code is similar to
ON: {"refreshbizlines": function ($ Event) {_vm.gotodetail (123)}} Therefore, the principle is that the subcomponents accesses the detection function of the parent component, and accessed, executing the function below under Refreshbizline gotodetail – is also the parent component

gotodetail function
Note
   
V-ON: refreshbizlines = “gotodetail”


Be sure to place the module name of your parent component call subcomponent.

I wish you a happy code.
 The above Vuejs 2.0 subcomponent Access / call the parent component instance is the full content of Xiaobian sharing to everyone, I hope to give you a reference, I hope everyone will support Tumi Cloud.                      
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment