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
