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")) // 取值
}
标签:全局变量,userId,js,userType,Vue,prototype,store From: https://www.cnblogs.com/Harrylsj/p/17853015.html