vue之session封装

vue之session封装

import Vue from 'vue'

const setSession = (key, value) => {
    
    
  value = JSON.stringify(value)
  sessionStorage.setItem(key, value)
}

const getSession = key => {
    
    
  if (key == '') return ''
  let retValue = sessionStorage.getItem(key)
  if (retValue == null) return ''
  return retValue
}
const delSesssion = key => {
    
    
  if (key) {
    
    
    sessionStorage.removeItem(key)
  }
}

const sortNo = (x, y) => {
    
    
  return x['sortNo'] > y['sortNo'] ? 1 : -1
}

export default {
    
    
  install(Vue, options) {
    
    
    ;(Vue.prototype.getSession = getSession),
      (Vue.prototype.setSession = setSession),
      (Vue.prototype.delSesssion = delSesssion),
      (Vue.prototype.sortNo = sortNo)
  }
}


Guess you like

Origin blog.csdn.net/weixin_43876684/article/details/86562383