多个页面调用了同一个自定义组件,组件内能否定义多个triggerEvent()以区分是哪个页面?

发布于 7 年前作者 xia4714401 次浏览最后编辑 7 年前来自 ask

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

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

      this.triggerEvent('customevent', {})      

      this.triggerEvent('customevent2', {})     

      this.triggerEvent('customevent3', {})      

      this.triggerEvent('customevent4', {}) 

    }
  }

})



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

0 回复
暂无回复