Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js vue会话存储从另一页检索值_Vue.js - Fatal编程技术网

Vue.js vue会话存储从另一页检索值

Vue.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)

我将会话值存储在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)

         }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的可能性。然后在发生*存储更改时启动它

您还可以在选项卡之间交换存储数据


我会将此作为评论发布,因为它不是完整的答案,但我没有足够的分数,抱歉。

检查浏览器会话存储,查看电子邮件是否成功存储