2016-09-30 8 views
1

ログアウト時にユーザーセッションを保存する方法を理解しようとしています。例えば複数のショッピングカート、取引、さらには過去の検索などがあります。私はバックエンドの言語全体に対してかなり新しいので、私はその問題についての指導を求めています。私はこの問題についてgoogle-fooでシェアを試したが、達成しようとしていることについての良い文書は見つけられていない。誰でも私を助け、案内することができますか?ユーザーセッションを保存する方法VueJS

ありがとうございました!

答えて

2

セッションをクッキーまたはサーバーに保存する必要があります。

vue-cookieは、ブラウザの格納に使用するのに適したコンポーネントです。

サーバーに格納する場合は、データのエンドポイントを作成して保存する必要があります。データベース、キャッシュファイル、Redisの、など

3

トライ使用ログインエリア内vue-session

例:領域にログインし

export default { 
    name: 'login', 
    methods: { 
     login: function() { 
      this.$http.post('http://somehost/user/login', { 
      password: this.password, 
      email: this.email 
      }).then(function (response) { 
      if (response.status === 200 && 'token' in response.body) { 
       this.$session.start() 
       this.$session.set('jwt', response.body.token) 
       Vue.http.headers.common['Authorization'] = 'Bearer ' + response.body.token 
       this.$router.push('/panel/search') 
      } 
      }, function (err) { 
      console.log('err', err) 
      }) 
     } 
    } 
} 

export default { 
    name: 'panel', 
    data() { 
    return { } 
    }, 
    beforeCreate: function() { 
    if (!this.$session.exists()) { 
     this.$router.push('/') 
    } 
    }, 
    methods: { 
    logout: function() { 
     this.$session.destroy() 
     this.$router.push('/') 
    } 
    } 
} 
関連する問題