这是一个基本的 hello world 网络组件。更改属性“who”时不会触发 attributeChangedCallback。检查 fiddle
MyElementProto.attributeChangedCallback = function(attr, oldVal, newVal) {
console.log('attributeChangedCallback triggered');
if (attr === 'who') {
this.setWho(newVal);
}
};
最佳答案
您需要使用 setAttribute
方法:
window.changeWhoAttr = function() {
var el = document.querySelector('#custom-tag');
el.setAttribute('who', 'Universe'); // Instead of el.who = 'Universe'
console.log('changeWhoAttr triggered');
}
关于javascript - Web 组件 : attributeChangedCallback not fired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36887757/