axios封装测试
This commit is contained in:
parent
cba1f67400
commit
6191e9c171
@ -25,6 +25,7 @@
|
||||
"dependencies": {
|
||||
"@electron-toolkit/preload": "^3.0.1",
|
||||
"@electron-toolkit/utils": "^3.0.0",
|
||||
"axios": "^1.7.2",
|
||||
"electron-updater": "^6.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -159,7 +159,10 @@ app.whenReady().then(() => {
|
||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
})
|
||||
|
||||
// 忽略证书错误
|
||||
app.commandLine.appendSwitch('ignore-certificate-errors')
|
||||
|
||||
createWindow()
|
||||
|
||||
|
30
src/renderer/src/utils/http.js
Normal file
30
src/renderer/src/utils/http.js
Normal file
@ -0,0 +1,30 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const base_url = ''
|
||||
|
||||
// 创建 axios 实例
|
||||
const instance = axios.create({
|
||||
baseURL: base_url,
|
||||
timeout: 10000,
|
||||
headers: {'X-Custom-Header': 'foobar'} // 默认请求头
|
||||
});
|
||||
|
||||
// 添加请求拦截器
|
||||
instance.interceptors.request.use(function (config) {
|
||||
// 在发送请求之前做些什么
|
||||
return config;
|
||||
}, function (error) {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
// 添加响应拦截器
|
||||
instance.interceptors.response.use(function (response) {
|
||||
// 对响应数据做点什么
|
||||
return response.data; // 假设你的后端返回的是 { data: {...} } 格式的数据
|
||||
}, function (error) {
|
||||
// 对响应错误做点什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
export default instance;
|
Reference in New Issue
Block a user