2017-05-27 5 views
0

私はログインシステムを持っています。ここでは、localstorage上のログインユーザーをkeeeしなければなりません。そして、ユーザーログを取得したら、ログインページにアクセスするたびに彼自身のページにリダイレクトします。なぜ私の財産は鉄のローカルストレージの値を反映しませんか?

マイテンプレート:

<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'プロパティでオブザーバーを使用する必要があります。

関連する問題