|
|
@@ -0,0 +1,35 @@
|
|
|
+import axios from 'axios'
|
|
|
+// export const baseURL = '666初始地址'
|
|
|
+export default axios.create({
|
|
|
+ baseURL: '666初始地址',
|
|
|
+ timeout: 5000
|
|
|
+})
|
|
|
+
|
|
|
+// // 请求拦截器
|
|
|
+// axios.interceptors.request.use(function (config) {
|
|
|
+// // 在发送请求之前做些什么:看看有没有token,如果有通过请求头的方式传递token
|
|
|
+// const token = localStorage.getItem('token')
|
|
|
+// if (token) { // 判断是否有token,有,则
|
|
|
+// // config.headers['Authorization'] = token
|
|
|
+// config.headers.Authorization = `Bearer ${token}`
|
|
|
+// }
|
|
|
+
|
|
|
+// return config
|
|
|
+// }, function (error) {
|
|
|
+// // 对请求错误做些什么
|
|
|
+// return Promise.reject(error)
|
|
|
+// })
|
|
|
+
|
|
|
+// // 添加响应拦截器
|
|
|
+// axios.interceptors.response.use(function (response) {
|
|
|
+// // 对响应数据做点什么--response就是发送每个请求的返回值
|
|
|
+// if (response.data.message === '用户信息验证失败') {
|
|
|
+// // Toast.fail('未登录,请先登录')
|
|
|
+// // 登录完之后能返回刚刚的页面
|
|
|
+// location.href = '#/login?redirectUrl=' + location.href
|
|
|
+// }
|
|
|
+// return response
|
|
|
+// }, function (error) {
|
|
|
+// // 对响应错误做点什么
|
|
|
+// return Promise.reject(error)
|
|
|
+// })
|