From 794884fc66867a1eabd4b2096d26020e1929fb18 Mon Sep 17 00:00:00 2001 From: chenkainan Date: Tue, 19 Aug 2025 09:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 5 ++ .env.production | 5 ++ src/libs/axios.js | 6 +- src/views/Home.vue | 207 ++++++++++++++++++++++---------------------- src/views/Index.vue | 20 +++++ 5 files changed, 137 insertions(+), 106 deletions(-) create mode 100644 .env.development create mode 100644 .env.production diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..73c4a95 --- /dev/null +++ b/.env.development @@ -0,0 +1,5 @@ +NODE_ENV='development' +# 请求域名前缀 +VUE_APP_URL='https://swsz.api.js-dyyj.com' +# 打包后输出目录 +VUE_APP_OUTPUTDIR='dist_dev' \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..8808c55 --- /dev/null +++ b/.env.production @@ -0,0 +1,5 @@ +NODE_ENV='production' +# 请求域名前缀 +VUE_APP_URL='https://api.sutenong.com' +# 打包后输出目录 +VUE_APP_OUTPUTDIR='dist' \ No newline at end of file diff --git a/src/libs/axios.js b/src/libs/axios.js index 728d487..d7fc7af 100644 --- a/src/libs/axios.js +++ b/src/libs/axios.js @@ -17,7 +17,7 @@ http.interceptors.request.use((config) => { config.baseURL = process.env.VUE_APP_URL; } - const token = store.state.user.userInfo.token; + const token = store.state.user?.userInfo?.token || ''; config.headers['token'] = token config.headers['Content-Type'] = 'application/json;charset=UTF-8'; @@ -84,7 +84,7 @@ http.interceptors.response.use(response => { }); // 请求方法挂载 -Vue.prototype.get = (params, url, loading = true) => { +Vue.prototype.get = (params, url, loading = false) => { return new Promise((resolve, reject) => { http.get(url, { params, @@ -99,7 +99,7 @@ Vue.prototype.get = (params, url, loading = true) => { }) } -Vue.prototype.post = (data, url, loading = true) => { +Vue.prototype.post = (data, url, loading = false) => { return new Promise((resolve, reject) => { http.post(url, data, { loading // 传递加载状态参数 diff --git a/src/views/Home.vue b/src/views/Home.vue index d0d2430..906682c 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,27 +1,27 @@