Vue.js vue会话存储从另一页检索值
我将会话值存储在login.htmlVue.js vue会话存储从另一页检索值,vue.js,Vue.js,我将会话值存储在login.html axios.post(this.url,data) .then( function (response ) { if(response.data.success){ window.location.href = "http://localhost/dairyweb/index.html" sessionStorage.setItem('email',this.email)
axios.post(this.url,data)
.then( function (response ) {
if(response.data.success){
window.location.href = "http://localhost/dairyweb/index.html"
sessionStorage.setItem('email',this.email)
}else {
alert(response.data.message)
}
}.bind(this)).catch(function (error) {
// bind to initialize an object
})
在index.html上,我想检索该值并使用它,但不起作用
computed: {
userType (){
return sessionStorage.getItem('email')
}
}
这是我如何找回的
{{userType}}
这在下一页不起作用。无错误只是静默Vue中的会话存储未显式绑定到存储它的窗口,这就是它无法正确保存的原因 您需要使用
窗口
对象:
window.sessionStorage.setItem('email',this.email)
旁边的返回window.sessionStorage.getItem('email')
或者,您可以使用一个将本地存储绑定到Vue对象的外部包,以便从this
调用this.$ls.set()
您还可以考虑使用postmessage的可能性。然后在发生*存储更改时启动它 您还可以在选项卡之间交换存储数据
我会将此作为评论发布,因为它不是完整的答案,但我没有足够的分数,抱歉。检查浏览器会话存储,查看电子邮件是否成功存储