js 全局变量

1、赋值并保存
import { setSessionStorage } from '@/store/index'
 
Vue.prototype.$userId = res.result.userInfo.id
Vue.prototype.$userType = res.result.userInfo.post
setSessionStorage()
2、index.js

export function setSessionStorage() {
var store ={

  userId : Vue.prototype.$userId,

  userType :Vue.prototype.$userType,

}
sessionStorage.setItem("store",JSON.stringify(store))
}

export function getStore() {
  return JSON.parse(sessionStorage.getItem("store")) // 取值
}

 

posted @ 2023-11-24 09:30  Harrylsj  阅读(39)  评论(0)    收藏  举报