The uniapp applet parent component calls the child component method

Answer: Cooperate with the mini program API => this.selectComponent("") to select the component, then use $vm to select the component instance, and then call the method, or data

1 Set the id of the component. If you have multiple terminals, please set the ref, class, and id according to the situation so that you can select the component through the mini program API (the method of the mini program, the API that supports the mini program in uniapp)

// 父组件调用
const child = this.selectComponent('#the-id') // 等于 { myField: 'myValue' }

Among the objects returned in child, the first item may look familiar, it is the Vue instance . So next you should know how to operate it. 

 

2 Call the method in the component

child.$vm.Method name()

How about it, it’s not strange, because, as emphasized in the uniapp official website, ref is only used for h5, and non-h5 is not supported.

Therefore, we need to borrow the mini program method to implement it, the parent tune method. 

Guess you like

Origin blog.csdn.net/tdjqqq/article/details/132807491