多个页面调用了同一个自定义组件,组件内能否定义多个triggerEvent()以区分是哪个页面?
发布于 6 年前 作者 xia47 14278 次浏览 来自 问答

一般来说,在子组件内定义this.triggerEvent()就可以调用父组件的方法了,如下

// 组件 my-component.js
Component({
  methods: {
    onTap: function(){

      this.triggerEvent('customevent', {})      

      this.triggerEvent('customevent2', {})     

      this.triggerEvent('customevent3', {})      

      this.triggerEvent('customevent4', {}) 

    }
  }

})



然后在不同的页面监听不同的customevent事件

回到顶部