javascript - 我在打字稿中有一个自定义事件,我只想创建一次自定义事件对象,而后者想使用相同的对象
问题描述
假设
export class PublishEvent {
public static DispatchEvent(eventName:string,data:any){
const customEvent = new CustomEvent(eventName, {
"detail": data
});
document.dispatchEvent(customEvent);
}
}
在我的代码中,当我调用 DispatchEvent 时,我每次都需要创建新的 CustomEvent。有没有所以我会创建一次对象并进一步更新数据。
解决方案
推荐阅读
- reactjs - 如何将值传递给路由中的另一个组件?
- ios - 从终端更改 Expo 中的配置文件
- excel - 将空值跳过到下一个工作表并粘贴到另一个具有 sama 名称表的工作簿
- linux - Curl 的证书问题
- ajax - 通过 Jquery Ajax 函数加载后不渲染 KnockoutJS 元素
- redis - 为什么redis在启动时不先加载rdb文件再加载aof文件?
- opengl - 片段着色器问题中的多个输出
- python - 我在我的 python 程序中对下面描述的问题使用的逻辑有什么问题?
- c++ - 在 macOS Mojave 上尝试 OpenCV 视频捕获时出现“中止陷阱:6”
- python - 使用 DRF 和 django-revproxy 时出现“异常:从请求的数据流中读取后无法访问正文”