如何使用 VueJS 保存用户会话? [英] How to save users sessions with VueJS?
本文介绍了如何使用 VueJS 保存用户会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想弄清楚如何在用户注销时保存用户会话.例如多个购物车、交易,甚至以前的搜索.我对整个后端语言还很陌生,我只是在寻求有关此事的指导.我已经在 google-foo 上尝试过我的分享,但没有找到任何关于我想要实现的目标的好的文档.
I am trying to figure out how to save users session when they log out. e.g. multiple shopping carts, transactions, and even previous searches. I am pretty new to the whole backend language and I am just seeking guidance on the matter. I have tried my share at google-foo for this matter, but have not found any good documentation on what I am trying to achieve.
有人可以帮助和/或指导我吗?
Can anyone help and/or guide me?
推荐答案
尝试使用 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('/')
}
}
}
这篇关于如何使用 VueJS 保存用户会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文