【发布时间】:2019-11-11 18:28:06
【问题描述】:
如何在 Stencil.js 组件中定义全局变量?
@ClickOutside()
someMethod() {
let editable = this.el.querySelector('.editable');
if (this.el.classList.contains('is-open')) {
this.el.classList.toggle('is-open');
editable.setAttribute('contenteditable',
editable.getAttribute('contenteditable') === 'true' ? 'false' : 'true');
}
}
openToolbar() {
let editable = this.el.querySelector('.editable');
if (editable.getAttribute('contenteditable') === 'true') {
return
}
this.el.classList.toggle('is-open');
editable.setAttribute('contenteditable',
editable.getAttribute('contenteditable') === 'true' ? 'false' : 'true');
}
这按预期工作,但我在两个单独的函数中重复自己。我想在外面定义第一个 let 变量,这样我就可以在两个函数中使用它。
【问题讨论】:
标签: javascript typescript jsx stenciljs