Dom-Если не обновляется после изменения переменной - PullRequest
0 голосов
/ 28 мая 2020

У меня проблема, когда на странице из стартового набора полимеров я установил для переменной значение true, но Dom-if, созданный в основном приложении, не перерисовывается, хотя, если я отображаю переменную в обычном виде, он меняется.

Вот код dom-if:

<app-location route="{{route}}" url-space-regex="^[[rootPath]]">
   </app-location>

   <app-route route="{{route}}" pattern="[[rootPath]]:page" data="{{routeData}}" tail="{{subroute}}">
   </app-route>

   <app-drawer-layout fullbleed="" narrow="{{narrow}}">
     <!-- Drawer content -->
     <template is=dom-if if='{{isLoggedIn}}'>
     <app-drawer id="drawer" slot="drawer" swipe-open="[[narrow]]">
       <app-toolbar class="menu">Menu</app-toolbar>
       <iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
         <a class="textMenu" name="view1" href="[[rootPath]]view1">3Deseos</a>
         <a class="textMenu" name="login" href="[[rootPath]]login">Regalar</a>
         <a class="textMenu" name="view3" href="[[rootPath]]view3">Mi Perfil</a>
       </iron-selector>
       <img class="fondoDeTres" src="./images/background.png">
     </app-drawer>
     </template>

     <template is=dom-if if='{{!isLoggedIn}}'>
     <app-drawer id="drawer" slot="drawer" swipe-open="[[narrow]]">
       <app-toolbar class="menu">Menu</app-toolbar>
       <iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
         <a class="textMenu" name="view1" href="[[rootPath]]view1">3Deseos</a>
         <a class="textMenu" name="login" href="[[rootPath]]login">Ingresar</a>
       </iron-selector>
       <img class="fondoDeTres" src="./images/background.png">
     </app-drawer>
     </template>

и здесь это код логического (я даже пробовал добавить наблюдателя, но он не работает) :

   isLoggedIn: {
     type: Boolean,
     value: false,
     notify: true,
     observer: '_loginStatusChanged'
   }

здесь наблюдатель:

   _loginStatusChanged(status){
     this.isLoggedIn=status;
     console.log("Cambio el Login a "+status);
   }

и скрипт, который его изменяет:

  submit(){
      console.log("requestSent");
      var xhr = new XMLHttpRequest();
      var url = "http://localhost:3000/api/login";
      var request = {
        username : this.username,
        password : this.password
      }
      var that=this;
      xhr.open("POST", url, true);
      xhr.setRequestHeader("Content-Type", "application/json");
      xhr.onreadystatechange = function () {
          if (xhr.readyState === 4 && xhr.status === 200) {
              var reply = JSON.parse(xhr.responseText);
              console.log(reply);
              that.set('isLoggedIn', reply);
              console.log(that.isLoggedIn);
          }
      };
      var data = JSON.stringify({request});
      xhr.send(data);
  }

Подсказки? Заранее спасибо!

1 Ответ

0 голосов
/ 28 мая 2020

Решаю это железом-localstorage. Я не знаю, лучший ли это способ, но ЕГО РАБОТАЕТ! : D

...