From 7d3a345843b470f527fa2cde33ccb8f23413b431 Mon Sep 17 00:00:00 2001 From: xuewuerduo <53554701+xuewuerduo@users.noreply.github.com> Date: Thu, 18 Jul 2024 22:58:05 +0800 Subject: [PATCH] =?UTF-8?q?22.=E5=B0=81=E8=A3=85axios=E5=92=8C=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E7=AE=A1=E7=90=86=E5=91=98=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/AxiosDr.js | 51 ++++++++++++++++++++++++++ src/views/admin/administrator/list.vue | 26 ++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/utils/AxiosDr.js diff --git a/src/utils/AxiosDr.js b/src/utils/AxiosDr.js new file mode 100644 index 0000000..71d01e7 --- /dev/null +++ b/src/utils/AxiosDr.js @@ -0,0 +1,51 @@ +/* + 作者: 邓瑞 + 版本: 1.0 + 网站: www.dengruicode.com + 日期: 2024-04-21 +*/ + +import axios from 'axios' + +const axiosInstance = axios.create({ // axios 实例 + //baseURL: "http://127.0.0.1:8008", + baseURL: import.meta.env.VITE_API_URL, + timeout: 5000 +}) + +const get = (url, data = {}) => { + return axiosInstance.get(url, { params: data }).then(response => response.data) +} + +const post = (url, data = null) => { + return axiosInstance.post(url, data).then(response => response.data) +} + +const postForm = (url, data = null) => { + return axiosInstance.post(url, data, { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + }) + .then(response => response.data) +} + +const postFile = (url, data = null) => { + return axiosInstance.post(url, data, { + headers: { + 'Content-Type': 'multipart/form-data' + } + }) + .then(response => response.data) +} + +const postToken = (url, token, data = null) => { + return axiosInstance.post(url, data, { + headers: { + 'Authorization': `Bearer ${token}` + } + }) + .then(response => response.data) +} + +export default { get, post, postForm, postFile, postToken } diff --git a/src/views/admin/administrator/list.vue b/src/views/admin/administrator/list.vue index f26cdcc..6f4bc44 100644 --- a/src/views/admin/administrator/list.vue +++ b/src/views/admin/administrator/list.vue @@ -15,13 +15,37 @@