Skip to content

Commit 250e7a3

Browse files
author
jiangjun123
committed
mock数据 配置调整
1 parent 784a599 commit 250e7a3

File tree

12 files changed

+247
-58
lines changed

12 files changed

+247
-58
lines changed

mock/user.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default [
2+
{
3+
url: '/api/getUers',
4+
method: 'get',
5+
response: () => {
6+
return {
7+
code: 200,
8+
message: 'success',
9+
data: {
10+
userId: 'sdf2223',
11+
userName: '小胡',
12+
},
13+
};
14+
},
15+
},
16+
];

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "hu-snail",
55
"scripts": {
66
"lint": "eslint \"src/**/*.{js,vue}\"",
7-
"dev": "vite --mode development",
7+
"dev": "cross-env NODE_ENV=development vite",
88
"build": "vite build --mode production",
99
"preview": "npm run build && vite preview",
1010
"lint:eslint": "eslint --cache --max-warnings 0 \"{src,mock}/**/*.{vue,ts,tsx}\" --fix",
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"axios": "^0.21.1",
1818
"element-plus": "^1.0.2-beta.65",
19+
"mockjs": "^1.1.0",
1920
"vue": "^3.0.5",
2021
"vue-router": "^4.0.10",
2122
"vuex": "^4.0.2"
@@ -25,15 +26,14 @@
2526
"@vitejs/plugin-vue": "^1.3.0",
2627
"@vue/compiler-sfc": "^3.0.5",
2728
"@vue/eslint-config-prettier": "^6.0.0",
28-
"amfe-flexible": "^2.2.1",
2929
"autoprefixer": "^10.3.1",
3030
"babel-eslint": "^10.1.0",
31+
"cross-env": "^7.0.3",
3132
"eslint": "^7.32.0",
3233
"eslint-plugin-prettier": "^3.4.0",
3334
"eslint-plugin-vue": "^7.15.0",
3435
"lint-staged": "^11.1.1",
3536
"postcss": "^8.3.6",
36-
"postcss-pxtorem": "^6.0.0",
3737
"prettier": "^2.3.2",
3838
"sass": "^1.37.0",
3939
"stylelint": "^13.13.1",
@@ -42,6 +42,7 @@
4242
"stylelint-config-standard": "^22.0.0",
4343
"vite": "^2.4.4",
4444
"vite-plugin-babel-import": "^2.0.5",
45+
"vite-plugin-mock": "^2.9.4",
4546
"vite-plugin-style-import": "^1.0.1"
4647
}
4748
}

postcss.config.js

-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,5 @@ module.exports = {
1212
],
1313
grid: true,
1414
},
15-
'postcss-pxtorem': {
16-
rootValue: 75,
17-
propList: ['*'],
18-
selectorBlackList: ['.el'],
19-
unitPrecision: 5,
20-
},
2115
},
2216
};

src/api/user.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import request from '@/utils/request.js';
2+
3+
export const getUser = () => {
4+
return request({ url: '/getUers', method: 'get' });
5+
};

src/components/HelloWorld.vue

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@
1515

1616
<script setup>
1717
import { onBeforeMount, defineProps } from 'vue';
18+
import { getUser } from '@/api/user.js';
1819
onBeforeMount(() => {
19-
console.log(2);
20+
getUserInfo();
2021
});
2122
defineProps({
2223
msg: String,
2324
});
25+
26+
const getUserInfo = async () => {
27+
getUser()
28+
.then((res) => {
29+
console.log(res);
30+
})
31+
.catch((err) => {
32+
console.log(err);
33+
});
34+
};
2435
</script>
2536

2637
<style lang="scss" scoped>

src/config/index.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
/**
2-
* @description 导出配置信息
3-
* @author hu-snail [email protected]
4-
*/
5-
import netConfig from './net.config';
6-
import setting from './setting';
7-
8-
module.exports = Object.assign({}, netConfig, setting);
1+
// ...

src/config/net.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* @author hu-snail [email protected]
44
*/
55

6-
export default {
6+
export const netConfig = {
77
// axios 基础url地址
8-
baseURL: process.env.NODE_ENV === 'development' ? 'https://xxx/api' : 'https://xxx/api',
8+
baseURL: process.env.NODE_ENV === 'development' ? 'http://localhost:8089/api' : 'https://xxx/api',
99
// 为开发服务器配置 CORS。默认启用并允许任何源,传递一个 选项对象 来调整行为或设为 false 表示禁用
1010
cors: true,
1111
// 根据后端定义配置

src/config/setting.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* vite相关的配置文件参考 https://cn.vitejs.dev/config/#define
55
*/
66

7-
export default {
7+
export const setting = {
88
//项目部署的基础路径
99
base: './',
1010
// 静态资源服务的文件夹 类型 string | false

src/plugin/index.JS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import 'amfe-flexible/index.js';
1+
// import 'amfe-flexible/index.js';

src/utils/request.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import Vue from 'vue';
21
import axios from 'axios';
3-
import {
4-
baseURL,
5-
contentType,
6-
invalidCode,
7-
noPermissionCode,
8-
requestTimeout,
9-
successCode,
10-
} from '@/config/index.js';
11-
12-
import store from '@/store';
13-
import router from '@/router';
2+
import { netConfig } from '@/config/net.config';
3+
const { baseURL, contentType, invalidCode, noPermissionCode, requestTimeout, successCode } =
4+
netConfig;
5+
import store from '@/store/index.js';
6+
import router from '@/router/index.js';
147
import { ElMessageBox, ElMessage } from 'element-plus';
158

169
// eslint-disable-next-line no-unused-vars
@@ -42,7 +35,8 @@ const handleCode = (code, msg) => {
4235
router.push({ path: '/401' }).catch(() => {});
4336
break;
4437
default:
45-
Vue.prototype.$baseMessage(msg || `后端接口${code}异常`, 'error');
38+
console.log(msg);
39+
// Vue.prototype.$baseMessage(msg || `后端接口${code}异常`, 'error');
4640
break;
4741
}
4842
};

vite.config.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ const path = require('path');
33
import vue from '@vitejs/plugin-vue';
44
import styleImport from 'vite-plugin-style-import';
55
import legacy from '@vitejs/plugin-legacy';
6-
7-
import {
6+
import { viteMockServe } from 'vite-plugin-mock';
7+
import { setting } from './src/config/setting';
8+
const {
89
base,
910
publicDir,
1011
outDir,
@@ -21,8 +22,7 @@ import {
2122
clearScreen,
2223
drop_console,
2324
drop_debugger,
24-
} from './src/config/index.js';
25-
25+
} = setting;
2626
// https://vitejs.dev/config/
2727
export default defineConfig({
2828
root: process.cwd(),
@@ -52,6 +52,9 @@ export default defineConfig({
5252
},
5353
],
5454
}),
55+
viteMockServe({
56+
supportTs: false,
57+
}),
5558
],
5659

5760
server: {
@@ -72,11 +75,6 @@ export default defineConfig({
7275
},
7376

7477
css: {
75-
css: {
76-
postcss: {
77-
plugins: [require('autoprefixer')],
78-
},
79-
},
8078
preprocessorOptions: {
8179
// 引入公用的样式
8280
scss: {
@@ -86,6 +84,7 @@ export default defineConfig({
8684
},
8785

8886
build: {
87+
target: 'es2015',
8988
outDir,
9089
assetsDir,
9190
sourcemap,
@@ -100,10 +99,12 @@ export default defineConfig({
10099
},
101100
terserOptions: {
102101
compress: {
102+
keep_infinity: true,
103103
drop_console,
104104
drop_debugger,
105105
},
106106
},
107+
chunkSizeWarningLimit: 2000,
107108
},
108109

109110
optimizeDeps: {

0 commit comments

Comments
 (0)