初始化
This commit is contained in:
15
until/config.js
Normal file
15
until/config.js
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
//api 请求路径 本地
|
||||
// http://chat.qxmier.com
|
||||
// http://vschat.qxmier.com
|
||||
const BASE_URL="http://chat.qxmier.com";
|
||||
|
||||
//api 请求路径 测试
|
||||
// const BASE_URL="https://h5.qxcms.com/api";
|
||||
|
||||
//IM app_key
|
||||
const IM_APP_TOKEN="67962a777e2b13bc6a4bde3ccd389d1e";
|
||||
export {
|
||||
BASE_URL,
|
||||
IM_APP_TOKEN
|
||||
}
|
||||
45
until/http.js
Normal file
45
until/http.js
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
// 导入封装好的axios实例
|
||||
import request from "./request.js";
|
||||
|
||||
const http = {
|
||||
/**
|
||||
* methods: 请求
|
||||
* @param url 请求地址
|
||||
* @param params 请求参数
|
||||
*/
|
||||
get(url, params) {
|
||||
const config = {
|
||||
method: "get",
|
||||
url: url,
|
||||
};
|
||||
if (params) config.params = params;
|
||||
return request(config);
|
||||
},
|
||||
post(url, params) {
|
||||
const config = {
|
||||
method: "post",
|
||||
url,
|
||||
}
|
||||
if (params) config.data = params;
|
||||
return request(config);
|
||||
},
|
||||
put(url, params) {
|
||||
const config = {
|
||||
method: "put",
|
||||
url,
|
||||
}
|
||||
if (params) config.params = params;
|
||||
return request(config);
|
||||
},
|
||||
delete(url, params) {
|
||||
const config = {
|
||||
method: "delete",
|
||||
url,
|
||||
}
|
||||
if (params) config.params = params;
|
||||
return request(config);
|
||||
},
|
||||
};
|
||||
|
||||
export default http;
|
||||
35
until/request.js
Normal file
35
until/request.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// src/utils/http.js
|
||||
import axios from 'axios';
|
||||
|
||||
// 创建axios实例
|
||||
const http = axios.create({
|
||||
baseURL: 'https://chat.qxmier.com', // API的基础路径
|
||||
timeout: 5000 // 请求超时时间
|
||||
});
|
||||
|
||||
// 请求拦截器
|
||||
http.interceptors.request.use(
|
||||
config => {
|
||||
// 在发送请求之前做些什么,例如添加token等
|
||||
// config.headers['token'] = `${uni.getStorageSync('token')?? ''}`;
|
||||
return config;
|
||||
},
|
||||
error => {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 响应拦截器
|
||||
http.interceptors.response.use(
|
||||
response => {
|
||||
// 对响应数据做点什么
|
||||
return response.data; // 根据实际情况可能需要返回response.data或其他处理后的数据
|
||||
},
|
||||
error => {
|
||||
// 对响应错误做点什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default http;
|
||||
Reference in New Issue
Block a user