diff --git a/public/config.js b/public/config.js index cbc37938..cb4a0e7f 100644 --- a/public/config.js +++ b/public/config.js @@ -5,7 +5,7 @@ const APP_CONFIG = { //标题 APP_NAME: "SCUI", - - //接口地址 - API_URL: "" + + //接口地址,如遇跨域需使用nginx代理 + API_URL: "https://www.fastmock.site/mock/44c807475f7eeba73409792255781935/api" } diff --git a/src/api/index.js b/src/api/index.js index 7f375899..04bdcf6c 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -12,7 +12,7 @@ import http from "@/utils/request"; const api = { default: { upload: { - url: `${config.MOCK_URL}/upload`, + url: `${config.API_URL}/upload`, name: "文件上传", post: async function(data){ return await http.post(this.url, data); @@ -21,51 +21,51 @@ const api = { }, user: { login: { - url: `${config.MOCK_URL}/login`, + url: `${config.API_URL}/login`, name: "登录获取用户菜单和权限,全部权限", get: async function(){ return await http.get(this.url); } }, login_demo: { - url: `${config.MOCK_URL}/login_user`, + url: `${config.API_URL}/login_user`, name: "登录获取用户菜单和权限,部分权限", get: async function(){ return await http.get(this.url); } }, list: { - url: `${config.MOCK_URL}/user_list`, + url: `${config.API_URL}/user_list`, name: "获取用户列表", get: async function(params={}){ return await http.get(this.url, params); } }, save: { - url: `${config.MOCK_URL}/post`, + url: `${config.API_URL}/post`, name: "新增编辑用户", post: async function(params={}){ - return await http.get(this.url, params); + return await http.post(this.url, params); } }, del: { - url: `${config.MOCK_URL}/post`, + url: `${config.API_URL}/post`, name: "删除用户", post: async function(params={}){ - return await http.get(this.url, params); + return await http.post(this.url, params); } } }, role: { select: { - url: `${config.MOCK_URL}/role`, + url: `${config.API_URL}/role`, name: "角色选择列表", get: async function(){ return await http.get(this.url); } }, list: { - url: `${config.MOCK_URL}/role`, + url: `${config.API_URL}/role`, name: "角色列表", get: async function(){ return await http.get(this.url); @@ -74,14 +74,14 @@ const api = { }, dic: { list: { - url: `${config.MOCK_URL}/dic_list`, + url: `${config.API_URL}/dic_list`, name: "字典列表", get: async function(){ return await http.get(this.url); } }, info: { - url: `${config.MOCK_URL}/dic_info`, + url: `${config.API_URL}/dic_info`, name: "字典明细", get: async function(params){ return await http.get(this.url, params); @@ -90,7 +90,7 @@ const api = { }, app: { list: { - url: `${config.MOCK_URL}/app`, + url: `${config.API_URL}/app`, name: "应用列表", get: async function(){ return await http.get(this.url); @@ -99,7 +99,7 @@ const api = { }, menu: { list: { - url: `${config.MOCK_URL}/login`, + url: `${config.API_URL}/login`, name: "菜单管理", get: async function(){ // 这里接口对象偷懒重复了登录接口 @@ -111,7 +111,7 @@ const api = { }, log: { list: { - url: `${config.MOCK_URL}/loglist`, + url: `${config.API_URL}/loglist`, name: "日志列表", get: async function(params){ return await http.get(this.url, params); @@ -120,14 +120,14 @@ const api = { }, demo: { page: { - url: `${config.MOCK_URL}/page`, + url: `${config.API_URL}/page`, name: "分页列表", get: async function(params){ return await http.get(this.url, params); } }, upload: { - url: `${config.MOCK_URL}/upload`, + url: `${config.API_URL}/upload`, name: "文件上传接口", post: async function(data){ return await http.post(this.url, data); diff --git a/src/config/index.js b/src/config/index.js index 5908c019..573cae25 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -6,10 +6,7 @@ const DEFAULT_CONFIG = { APP_VER: "1.1.16", //接口地址 - API_URL: "", - - //MOCK接口地址 - MOCK_URL: "https://www.fastmock.site/mock/44c807475f7eeba73409792255781935/api", + API_URL: "/api", //TokenName TOKEN_NAME: "Authorization", diff --git a/vue.config.js b/vue.config.js index ad9231ed..644197e8 100644 --- a/vue.config.js +++ b/vue.config.js @@ -7,9 +7,19 @@ module.exports = { // build编译后不生成资源MAP文件 productionSourceMap: false, + //开发服务,build后的生产模式还需nginx代理 devServer: { open: false, //运行后自动打开游览器 - port: 2800 //挂载端口 + port: 2800, //挂载端口 + proxy: { + '/api': { + target: 'https://www.fastmock.site/mock/44c807475f7eeba73409792255781935/api', + ws: true, + pathRewrite: { + '^/api': '/' + } + } + } }, chainWebpack: config => {