0
点赞
收藏
分享

微信扫一扫

微信小程序 - 子组件触发父组件函数(triggerEvent)

莞尔小迷糊 2022-02-17 阅读 92

前言

在小程序里,组件间通信与传统 Vue 有所区别。

解决方案

其实官方文档已介绍 this.triggerEvent 与其参数,下面是更加易于理解的例子。


子组件(help):

<view bindtap="onTap">点我触发父组件函数方法</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('当onTap执行时我就执行了')
}

写在后面

当然,该示例只是让您易于理解,更多写法及注意事项请参考官方文档。

举报

相关推荐

0 条评论