I have following code:
export class ViTextfield extends LitElement
{
static get properties() {
return {
value: { type: String },
}
onChange(e) { console.log(e.target.value) }
render()
{
return html`
<div>
<div>
<input id="vi-input"
type="text"
value="${this.value}"
@change=${this.onChange} />
</div>
</div>
`
}
目前一切正常运行。 现在,使用我的组件的开发人员应该能够通过属性来设置值,例如:
document.getElementById('myComponent').value = 1;
现在有两个问题: 1)值本身没有更新,2)onchange事件没有触发
第一个问题我通过改变进行了修复
value="${this.value}"
to
.value="${this.value}"
即使我不知道为什么它能够工作(在网上找到了这个技巧)。
但是仍然无法触发onChange事件...