工作问题(代码含义)

69 阅读1分钟

Cookie的使用 setCookie(name, value, exdays) { // name :表示cookie的名称,比如token // value :表示cookie的值 // exdays :表示cookie的有效时间 var d = new Date(); d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); var expires = 'expires=' + d.toGMTString(); document.cookie = name + '=' + value + '; ' + expires; }, // 获取cookie getCookie(name) { var ret; var m; if (typeof name === 'string' && name !== '') { if ( (m = String(document.cookie).match( new RegExp('(?:^| )' + name + '(?:(?:=([^;]*))|;|$)') )) ) { ret = m[1] ? decodeURIComponent(m[1]) : ''; } } return ret; }, delCookie(key) { var date = new Date(); date.setTime(date.getTime() - 1); var delValue = this.getCookie(key); if (!!delValue) { document.cookie = key + '=' + delValue + ';expires=' + date.toGMTString(); } },

res?.data?.state的作用
 window.location = `${res.data.data}` + '?referer=' +  encodeURIComponent(window.location.href);的作用及输出
 

http.interceptors.response.use( (res) => { console.log(res.data); if (res?.data?.state === 401) { window.location = ${res.data.data} + '?referer=' + encodeURIComponent(window.location.href); } else { return res?.data; } }, (e) => { console.info(%c ${e.message}. at /src/utils/http.js, 'font-size:1.2em;font-weight:bold;background-color:#FED;color:#F91;'); } );

import * as的使用

理解这个函数 // 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题 const originalPush = VueRouter.prototype.push; VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(function (err) { console.log(err); }); };

configureWebpack: { plugins: [ new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'windows.jQuery': 'jquery', }), ], },