kun 19/10/1/20:45

This commit is contained in:
沈学坤
2019-10-01 20:41:35 +08:00
parent 07ac335de2
commit fdc595eadd
10 changed files with 395 additions and 261 deletions

View File

@@ -1,38 +0,0 @@
import axios from 'axios'
import router from '../../src/router'
// axios 配置
axios.defaults.timeout = 7200
axios.defaults.baseURL = ''
// test使用的
window.localStorage['token'] = JSON.stringify('shenxuekundetoken')
// http request 拦截器
axios.interceptors.request.use(
config => {
if (localStorage.token) {
// 判断token是否存在
config.headers.Authorization = localStorage.token // 将token设置成请求头
}
return config
},
err => {
return Promise.reject(err)
}
)
// http response 拦截器
axios.interceptors.response.use(
response => {
if (response.data.errno === 999) {
router.replace('/')
console.log('token过期')
}
return response
},
error => {
return Promise.reject(error)
}
)
export default axios

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-unused-expressions */
// 使用递归遍历所有属性判断是否 在对象里面匹配到值 借鉴js对象深拷贝的方式
function loopObj (searkey, obj) {
let bool = false
@@ -52,6 +53,21 @@ let tool = {
return !!~filters[key].indexOf(item[key])
})
})
},
/**
* 数组对象去重
* @param {*} arr 目标数组
* @param {*} reference 去重参数
*/
arrayHeavy: function unique (arr, reference) {
let map = new Map()
arr.forEach((item, index) => {
if (!map.has(item[reference])) {
map.set(item[reference], item)
}
})
return [...map.values()]
}
}