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


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM