【问题标题】:how to retrieve the value of a key in session storage如何在会话存储中检索键的值
【发布时间】:2022-01-19 19:01:05
【问题描述】:

如何在会话存储中检索键的值?我想在条件下测试会话存储中键的值,但它返回否定结果,但值“学生”是“角色”键的值,这是代码上的模式。

this.$q.sessionStorage.set('current_user', infos)
this.$q.sessionStorage.set('fullname', fullname)
this.$q.sessionStorage.set('roles', roles)

const professorRole = sessionStorage.getItem("roles")
const studentRole = sessionStorage.getItem("roles")

//console.log("stu " + professorRole);

if (studentRole !== null && studentRole.indexOf(2) === "student") {
    
    console.log('email exists');
} else  {
    console.log('email not ok');
}

【问题讨论】:

  • this.$q.sessionStoragesessionStorage 看起来不像。

标签: vue.js session-variables


【解决方案1】:

你可以使用任何一种方法

getKey (index) => String,nullgetAllKeys () => Array

this.$q.sessionStorage

在会话存储中检索键的值

例子:

let keys = this.$q.sessionStorage.getAllKeys()

【讨论】:

    猜你喜欢
    • 2017-05-07
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-24
    • 2014-09-10
    • 1970-01-01
    相关资源
    最近更新 更多