no message
This commit is contained in:
54
utils/http.js
Normal file
54
utils/http.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
const baseUrl = "https://interviewexperience.gter.net";
|
||||
// 指定后端返回的基本数据类型
|
||||
|
||||
const fetch = async (url, options) => {
|
||||
await nextTick(); //解决刷新页面useFetch无返回
|
||||
url = url.indexOf('https://') > -1 ? url : baseUrl + url;
|
||||
|
||||
options['headers'] = {
|
||||
authorization: "7a89997c2ccd8cb5ed8cb20d843dafdd"
|
||||
}
|
||||
// 9c92af854f552bbd2aab43230bcf8438 headers authorization
|
||||
return new Promise((resolve, reject) => {
|
||||
useFetch(url, { ...options })
|
||||
.then(({ data, error }) => {
|
||||
if (error.value) {
|
||||
reject(error.value);
|
||||
return;
|
||||
}
|
||||
const value = data.value;
|
||||
if (value.code === 201) {
|
||||
ElMessage({
|
||||
message: value.message,
|
||||
type: "error",
|
||||
});
|
||||
}
|
||||
resolve(value);
|
||||
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default new (class Http {
|
||||
get(url, params) {
|
||||
return fetch(url, { method: "get", params });
|
||||
}
|
||||
|
||||
post(url, body) {
|
||||
return fetch(url, { method: "post", body });
|
||||
}
|
||||
|
||||
put(url, body) {
|
||||
return fetch(url, { method: "put", body });
|
||||
}
|
||||
|
||||
delete(url, body) {
|
||||
return fetch(url, { method: "delete", body });
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user