我把下面的东西混合在一起。但是,dispatchEvent没有连接到this。我得到了错误Cannot read property 'dispatchEvent' of undefined。
因此,我使用了window.dispatchEvent,但父元素不会捕获该事件。你知道我能做些什么来激发一个混合中的事件吗?
fetchError(response) {
...
this.dispatchEvent(new CustomEvent(
'http-error', {bubbles: true, detail: msg, composed: true}
));
return Promise.reject(new Error(response.statusText));
}发布于 2019-12-22 19:43:35
您可能需要绑定该方法
将以下内容添加到您的混合中:
constructor() {
super();
this.fetchError = this.fetchError.bind(this)
}https://stackoverflow.com/questions/59441289
复制相似问题