axios中对cookie的封装

来源:互联网 发布:智多星项目造价软件 编辑:程序博客网 时间:2024/05/22 00:50
function isStandardBrowserEnv() {    if(typeof navigator !== 'undefined' && navigator.product === 'ReactNative'){        return false;    }    return (        typeof window !== 'undefined' &&        typeof document !== 'undefined'    );}function isNumber(val) {    return typeof val === 'number';}function isString(val) {    return typeof val === 'string';}var cookies = (isStandardBrowserEnv() ?  (function standardBrowserEnv(){    return {        write: function write(name, value, expires, path, domain, secure) {            var cookie = [];            cookie.push(name + '=' + encodeURIComponent(value));            if(isNumber(expires)) {                cookie.push('expires=' + new Date(expires).toGMTString());            }            if(isString(path)) {                cookie.push('path=' + path);            }            if(isString(domain)) {                cookie.push('domain=' + domain);            }            if(secure === true) {                cookie.push('secure');            }            document.cookie = cookie.join('; ');        },        read: function read(name) {            var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));            return (match ? decodeURIComponent(match[3]) : null);        },        remove: function remove(name) {            this.write(name, '', Date.now() - 86400000);        }    };  })() :  (function nonStandardBrowserEnv(){      return {          write: function write() {},          read: function read() { return null; },          remove: function remove() {}      };  })());
原创粉丝点击