From 09fc3a3d1022f18c414f34c290c2ba2646ec9f8f Mon Sep 17 00:00:00 2001 From: yuanjunbin Date: Thu, 5 Oct 2023 18:03:13 +0800 Subject: [PATCH] update --- stock-forcast-web/public/index.html.bak | 17 --------- stock-forcast-web/request/request.js.bak | 44 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 17 deletions(-) delete mode 100644 stock-forcast-web/public/index.html.bak create mode 100644 stock-forcast-web/request/request.js.bak diff --git a/stock-forcast-web/public/index.html.bak b/stock-forcast-web/public/index.html.bak deleted file mode 100644 index ca60643..0000000 --- a/stock-forcast-web/public/index.html.bak +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - <%= htmlWebpackPlugin.options.title %> - - - -
- - - diff --git a/stock-forcast-web/request/request.js.bak b/stock-forcast-web/request/request.js.bak new file mode 100644 index 0000000..8590ec1 --- /dev/null +++ b/stock-forcast-web/request/request.js.bak @@ -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 +