Reference js file in WeChat applet js page-child page js uses methods in parent page js or calls parent page data

Use parent page data or call methods in child pages

Step 1: Get the current page stack
Insert picture description here

  let pages = getCurrentPages();

Get data: Parent page method includes parameters
Insert picture description here
Part 2: Call method or use parameters

 pages[0].方法名();

The child component passes the value to the parent component

this.triggerEvent('父组件接收值的方法名',data);//data为要传递的值 可选

Invoke child component method in parent component

//父组件html中
<子组件  id="my-comoponent" ></子组件>
//父组件js中//在需要调用子组件方法的位置上: 
let child = this.selectComponent('#my-comoponent') ;//获取子组件实例this
child.子组件定义的方法()

Official WeChat Mini Program document address: https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html

Guess you like

Origin blog.csdn.net/men_gqi/article/details/112648676