2017-05-27 56 views
0

我有一個登錄系統,我需要在localstorage上登錄用戶,一旦用戶登錄,我想在他訪問登錄頁面時將他重定向到他自己的頁面。爲什麼我的房產不會反映鐵本地存儲價值?

我的模板:

<iron-localstorage name="user-storage" value="{{storedUser}}"></iron-localstorage> 

我的目標:

 static get properties() { 
      return { 
       storedUser: { 
        type: Object, 
        notify: true 
       }, 
       ... 
      } 
     } 

我想這樣做:

 redirect() { 
      console.log(this.storedUser); 
      if(this.storedUser) { 
       // Redirect user or admin to their own homescreen 
       if(this.storedUser.role == 'user') 
        this.set('route.path', '/homescreen-usuario'); 
       else if(this.storedUser.role == 'admin') 
        this.set('route.path', '/homescreen-admin'); 
       else 
        this.set('route.path', '/my-view404'); 
      } 
     } 

但第一行始終記錄 「不確定」。

回答

0

您應該使用'on-iron-localstorage-load-empty'和'on-iron-localstorage-load'事件來對存儲事件做出反應,或者您可以在'storedUser'屬性上使用觀察者。

相關問題