Taro + React 全局event 的使用
作者:互联网
1.在入口文件 aap.tsx
import { Events } from '@tarojs/taro' globalData = { event:new Events() } 2.发射事件 function tt(){ const event = Taro.getApp()?.$app?.globalData?.event; event.trigger('eventTest','123') } 3.接收事件 useEffect(()=>{ const event = Taro.getApp()?.$app?.globalData?.event; event.on('eventTest',res=>{ console.log(res,"接收") }) })标签:Taro,app,event,React,const,globalData,Events 来源: https://www.cnblogs.com/daifuchao/p/16378913.html