标签:code defaults ons fun tor comm ESS 布尔值 headers
/** * 设置axios的全局的header,用于项目中的axios的封装文件 * @param {axios对象} axiosObj */ function setEncryptHeader(axiosObj){ if(!axiosObj){ return; } let isEncrypt = getEncryptStorage(); if(typeof isEncrypt == ‘boolean‘){ axiosObj.defaults.headers.common[‘is-Encrypt‘] = isEncrypt;//设置全局的axios头部 } } /** * 设置storage的isEncrypt * @param {是否加密的布尔值} bool */ function setEncryptStorage(bool){ console.log(bool) sessionStorage.setItem(‘isEncrypt‘,bool);//设置sessionStorage的isEncrypt; } function getEncryptStorage(){ let isEncrypt = sessionStorage.getItem(‘isEncrypt‘)?JSON.parse(sessionStorage.getItem(‘isEncrypt‘)):null; //从sessionStorage中取isEncrypt; return isEncrypt; } const sfEncrypt = { setEncryptHeader: setEncryptHeader, setEncryptStorage: setEncryptStorage, getEncryptStorage: getEncryptStorage } module.exports = sfEncrypt; /* exports.sfEncrypt = { setEncryptHeader: setEncryptHeader, setEncryptStorage: setEncryptStorage, getEncryptStorage: getEncryptStorage }; */
标签:code defaults ons fun tor comm ESS 布尔值 headers
原文地址:https://www.cnblogs.com/lw5116/p/12127333.html