我想弄清楚如何保存用戶會話時,他們註銷。例如多個購物車,交易,甚至以前的搜索。我對整個後端語言都很陌生,我只是在尋求這方面的指導。我已經在這個問題上嘗試了我在google-foo上的分享,但還沒有找到我想要實現的任何好文檔。任何人都可以幫助和/或指導我嗎?如何保存用戶會話VueJS
謝謝!
我想弄清楚如何保存用戶會話時,他們註銷。例如多個購物車,交易,甚至以前的搜索。我對整個後端語言都很陌生,我只是在尋求這方面的指導。我已經在這個問題上嘗試了我在google-foo上的分享,但還沒有找到我想要實現的任何好文檔。任何人都可以幫助和/或指導我嗎?如何保存用戶會話VueJS
謝謝!
您需要將會話存儲在cookie中或服務器上。
vue-cookie將是一個很好的組件用於瀏覽器存儲。
如果您要存儲在服務器上,您需要爲數據創建端點並以某種方式存儲它;一個數據庫,緩存文件,Redis的等等
嘗試使用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('/')
}
}
}