微信小程序-调用组件内方法(父组件调用子组件)

1、定义子组件

定义一个tip组件,在tip.json中将component设置为true

{
  "component": true,
  "usingComponents": {}
}

在tip.js中设置被调用方法

...
showMyTips(content) {
    console.log(content)
},
...

2、引入组件

在index页面引入组件

index.json

{
  "usingComponents": {
    "tip":"/components/tip"
  },
  "disableScroll":true
}

index.wxml

<tip id="tip"></tip>

3、调用方法

调用tip组件中的方法

index.js

this.selectComponent("#tip").showMyTips('哈哈哈')

  

component
原文地址:https://www.cnblogs.com/sunday123/p/12911824.html