日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

微信小程序 - 子組件觸發(fā)父組件函數(shù)(triggerEvent)

作者:王佳斌 更新時(shí)間: 2022-02-27 編程語言

前言

類似 Vuethis.$emit(),子組件可執(zhí)行父組件的函數(shù)方法。

在小程序里,組件間通信與傳統(tǒng) Vue 有所區(qū)別。

解決方案

官方文檔:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html

其實(shí)官方文檔已介紹 this.triggerEvent 與其參數(shù),下面是更加易于理解的例子。


子組件(help):

<view bindtap="onTap">點(diǎn)我觸發(fā)父組件函數(shù)方法</view>
properties:{ text: String },
methods:{
    onTap(event) {
        this.triggerEvent("tapping", {
            text: this.propertie.text
        },{})
    }
}

父組件:

<help text="ok" bind:tapping="onPost" />
onPost(event) {
	console.log(event.detail.text)
    console.log('當(dāng)onTap執(zhí)行時(shí)我就執(zhí)行了')
}

寫在后面

當(dāng)然,該示例只是讓您易于理解,更多寫法及注意事項(xiàng)請參考官方文檔。

原文鏈接:https://wangjiabin.blog.csdn.net/article/details/122981498

欄目分類
最近更新