2017-05-27 69 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'属性上使用观察者。

相关问题