javascript - 触发全球事件 Polymer 2
问题描述
我正在尝试为我的界面创建一个错误处理对话框。该对话框将仅显示来自 Iron ajax 的错误消息。我能够访问此消息并希望在 ajax 返回错误时触发一个事件。这是触发事件的代码:
testError(e) {
const err = e.detail.request.xhr.response.message;
this.dispatchEvent(new Event('error'));
}
这是添加事件监听器的代码:
class ErrorHandling extends Polymer.Element {
static get is() { return 'error-handling'; }
static get properties() {
return {
}
}
constructor() {
super();
this._boundListener = this.error.bind(this);
}
connectedCallback() {
super.connectedCallback();
window.addEventListener('error', this._boundListener);
console.log("connectedCallback ran");
}
disconnectedCallback() {
super.disconnectedCallback();
window.removeEventListener('error', this._boundListener);
console.log("disconnectedCallback ran");
}
_boundListener(e) {
console.log("boundlistener ran");
}
我已通读文档以尝试找出为什么这不起作用但没有成功。为什么这不起作用?
解决方案
推荐阅读
- flutter - 如何在 SimpleAutoCompleteTextField 中使用验证器
- security - Ansible:按需询问保管库密码(仅在需要时)
- python - 使用 SSL 的 DB2 连接问题。协议特定错误代码:“420”,SQLSTATE=08001
- javascript - 使用 Reflux Actions 等待完成多个请求
- node.js - 如何使用 nodejs/expressjs 删除目录中超过 6 个月的文件?
- html - 为什么两个元素不在同一行,宽度为 80% 和 20% CSS
- android - 我想自由发布我的移动应用,而不是从 AppStore 和 GooglePlay 发布
- html - 在居中的表单内添加响应式图像
- xaml - 当 Observable Collection 改变对象状态时如何改变 Gridview Item UI
- ros - 为什么我一直收到此错误消息?xxx.so 未定义对 `absl::StrCat[abi:cxx11](absl::AlphaNum const& ...)` 的引用