setCache/index.js

/**
 * 功能:写入缓存数据
 * @param {string} key
 * @param {any} value
 * @param {string} type: 缓存类型 'local'(默认) / session;
 * @returns {undefined} undefined
 */
function setCache(key='', value='', type = "local") {
    switch (type) {
      case "session":
        sessionStorage.setItem(key, JSON.stringify(value));
        break;
      default:
        localStorage.setItem(key, JSON.stringify(value));
        break;
    }
  }
  export default setCache