Browse Source

update

master
yuanjunbin 2 years ago
parent
commit
09fc3a3d10
2 changed files with 44 additions and 17 deletions
  1. +0
    -17
      stock-forcast-web/public/index.html.bak
  2. +44
    -0
      stock-forcast-web/request/request.js.bak

+ 0
- 17
stock-forcast-web/public/index.html.bak View File

@@ -1,17 +0,0 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>tothefor.png">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

+ 44
- 0
stock-forcast-web/request/request.js.bak View File

@@ -0,0 +1,44 @@
import axios from 'axios'

const request = axios.create({
baseURL: 'http://127.0.0.1:8081',
timeout: 10000
})

// request 拦截器
request.interceptors.request.use(config => {
config.headers['Content-Type'] = 'application/json;charset=utf-8';

// let usertoken = localStorage.getItem("token")?JSON.parse(localStorage.getItem("token")):null

let usertoken = localStorage.getItem("token")

config.headers['token'] = usertoken; // 设置请求头
return config
}, error => {
return Promise.reject(error)
});

// response 拦截器
request.interceptors.response.use(
response => {
let res = response.data;
// 如果是返回的文件
if (response.config.responseType === 'blob') {
return res
}
// 兼容服务端返回的字符串数据
if (typeof res === 'string') {
res = res ? JSON.parse(res) : res
}
return res;
},
error => {
// console.log('err' + error) // for debug
return Promise.reject(error)
}
)


export default request


Loading…
Cancel
Save