diff --git a/docker/nginx.conf b/docker/nginx.conf index 5374e1c..9c2213a 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -14,6 +14,11 @@ server { proxy_pass http://192.168.3.98:1001; } + # mock 跨域 + location ~/api/ { + proxy_pass http://192.168.3.98:1001; + } + error_page 404 404.html; location = /50x.html { diff --git a/src/api/test.ts b/src/api/v1/test.ts similarity index 100% rename from src/api/test.ts rename to src/api/v1/test.ts diff --git a/src/router/index.ts b/src/router/index.ts index 44674b8..d72a640 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,4 +1,4 @@ -import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'; +import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'; const routes: Array = [ { @@ -14,7 +14,7 @@ const routes: Array = [ */ const router = createRouter({ history: - process.env.NODE_ENV === 'production' ? createWebHashHistory(process.env.BASE_URL) : createWebHashHistory(process.env.BASE_URL), + process.env.NODE_ENV === 'production' ? createWebHashHistory(process.env.BASE_URL) : createWebHistory(process.env.BASE_URL), routes, }); diff --git a/src/utils/request-mock.ts b/src/utils/request-mock.ts new file mode 100644 index 0000000..1484775 --- /dev/null +++ b/src/utils/request-mock.ts @@ -0,0 +1,23 @@ +import axios from 'axios'; + +const request = axios.create({ + baseURL: '/mock', + timeout: 10000, +}); + +// 请求拦截器 +request.interceptors.request.use(config => { + return config; +}); + +// 响应拦截器 +request.interceptors.response.use( + response => { + return response.data; + }, + error => { + return Promise.reject(new Error('网络错误')); + }, +); + +export default request; diff --git a/vue.config.js b/vue.config.js index f20a569..7271944 100644 --- a/vue.config.js +++ b/vue.config.js @@ -27,6 +27,10 @@ module.exports = defineConfig({ target: process.env.VUE_APP_URL, changeOrigin: true, }, + '/mock': { + target: process.env.VUE_APP_URL, + changeOrigin: true, + }, }, }, configureWebpack: {