分享一个封装localStorage的工具类

分类:Vue 0 186
༺X.K༻_浅浅
发布日期:2019-06-11
export const TOKEN_KEY = 'token'
export const TOURL_KEY = 'tourl'
export const TOUID_KEY = 'uid'
// 设置token
export const setToken = (token) => {
localStorage.setItem(TOKEN_KEY, token)
}
// 获取token
export const getToken = () => {
const token = localStorage.getItem(TOKEN_KEY)
if (token) return token
else return false
}
// 记录url
export const setToUrl = (toUrl) => {
localStorage.setItem(TOURL_KEY, toUrl)
}
// 获取url
export const getToUrl = () => {
return localStorage.getItem(TOURL_KEY)
}
// 记录登录状态
export const setUid = (Uid) => {
localStorage.setItem(TOUID_KEY, Uid)
}
// 获取登录状态
export const getUid = () => {
return localStorage.getItem(TOUID_KEY)
}


回帖
  • 消灭零回复