微信小程序-調用組件內方法(父組件調用子組件)


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