Javascript 在此.classList.add()之后使用this.updateStyles()

Javascript 在此.classList.add()之后使用this.updateStyles(),javascript,polymer,Javascript,Polymer,我有这样一个组件(小、短、甜): :主机(.main-ent){ --原色:var(--paper-blue-600); } :主机(.main all){ --原色:var(--paper-purple-700); } 聚合物({ 是:“我的应用程序”, 特性:{ 网站信息:{ 类型:对象, 通知:正确, }, 附:函数(){ log(“SITEINFO(SHORT):”,this.SITEINFO.SHORT); this.classList.add('main-'+this.siteI

我有这样一个组件(小、短、甜):



:主机(.main-ent){
--原色:var(--paper-blue-600);
}
:主机(.main all){
--原色:var(--paper-purple-700);
}
聚合物({
是:“我的应用程序”,
特性:{
网站信息:{
类型:对象,
通知:正确,
},
附:函数(){
log(“SITEINFO(SHORT):”,this.SITEINFO.SHORT);
this.classList.add('main-'+this.siteInfo.short);
//this.async(函数(){
this.updateStyles();
//});
},
});
我遇到的问题是,如果没有
this.async()
,有时(比如说8次中的一次)
this.updateStyles()
似乎不起作用:原色保持“错误”。 我甚至不确定这个问题是否通过
this.async()解决了,或者只是缓解了

所以

  • 问题的根源是什么
  • this.async()
    真的修复了它吗
  • 如果没有,那是什么

    • 尝试清理CSS类。首先删除不再需要的类,然后设置新类

      this.classList.remove('unneeded_class');
      this.classList.add('new_class');
      

      为什么没有任何解释就被否决了?这没有帮助。如果这不是一个好的解决方案,我想知道为什么。
      this.classList.remove('unneeded_class');
      this.classList.add('new_class');