2 | 用户名:{{ mainStore.name }}
长度:{{ mainStore.nameLength }}
3 |
4 |
5 |
6 |
7 | naive-ui
8 |
9 |
10 |
22 |
23 |
28 |
--------------------------------------------------------------------------------
/vite.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import vue from '@vitejs/plugin-vue'
3 | import path from 'path'
4 | //@ts-ignore
5 | import viteCompression from 'vite-plugin-compression'
6 |
7 | // https://vitejs.dev/config/
8 | export default defineConfig({
9 | base: './', //打包路径
10 | plugins: [
11 | vue(),
12 | // gzip压缩 生产环境生成 .gz 文件
13 | viteCompression({
14 | verbose: true,
15 | disable: false,
16 | threshold: 10240,
17 | algorithm: 'gzip',
18 | ext: '.gz',
19 | }),
20 | ],
21 | // 配置别名
22 | resolve: {
23 | alias: {
24 | '@': path.resolve(__dirname, 'src'),
25 | },
26 | },
27 | css: {
28 | preprocessorOptions: {
29 | scss: {
30 | additionalData: '@import "@/assets/style/main.scss";',
31 | },
32 | },
33 | },
34 | //启动服务配置
35 | server: {
36 | host: '0.0.0.0',
37 | port: 8000,
38 | open: true,
39 | https: false,
40 | proxy: {},
41 | },
42 | // 生产环境打包配置
43 | //去除 console debugger
44 | build: {
45 | terserOptions: {
46 | compress: {
47 | drop_console: true,
48 | drop_debugger: true,
49 | },
50 | },
51 | },
52 | })
53 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.0.0",
3 | "license": "ISC",
4 | "scripts": {
5 | "dev": "vite",
6 | "build:dev": "vite build --mode development",
7 | "build:pro": "vite build --mode production",
8 | "serve": "vite preview",
9 | "lint": "eslint src --fix --ext .ts,.tsx,.vue,.js,.jsx",
10 | "prettier": "prettier --write .",
11 | "prepare": "husky install"
12 | },
13 | "dependencies": {
14 | "axios": "^0.24.0",
15 | "naive-ui": "^2.21.2",
16 | "nprogress": "^0.2.0",
17 | "pinia": "^2.0.0-rc.10",
18 | "vfonts": "^0.1.0",
19 | "vue": "^3.2.2",
20 | "vue-router": "4"
21 | },
22 | "devDependencies": {
23 | "@babel/types": "^7.16.0",
24 | "@types/node": "^16.11.10",
25 | "@types/nprogress": "^0.2.0",
26 | "@typescript-eslint/eslint-plugin": "^5.4.0",
27 | "@typescript-eslint/parser": "^5.4.0",
28 | "@vitejs/plugin-vue": "^1.2.5",
29 | "@vue/compiler-sfc": "^3.0.5",
30 | "autoprefixer": "^10.4.0",
31 | "dart-sass": "^1.25.0",
32 | "eslint": "^8.3.0",
33 | "eslint-config-prettier": "^8.3.0",
34 | "eslint-plugin-prettier": "^4.0.0",
35 | "eslint-plugin-vue": "^8.1.1",
36 | "husky": "^7.0.4",
37 | "lint-staged": "^12.1.2",
38 | "mrm": "^3.0.10",
39 | "postcss": "^8.4.4",
40 | "prettier": "^2.4.1",
41 | "sass": "^1.44.0",
42 | "typescript": "^4.5.2",
43 | "vite": "^2.4.2",
44 | "vite-plugin-compression": "^0.3.6",
45 | "vite-plugin-eslint": "^1.3.0",
46 | "vue-tsc": "^0.0.24"
47 | },
48 | "husky": {
49 | "hooks": {
50 | "pre-commit": "lint-staged"
51 | }
52 | },
53 | "lint-staged": {
54 | "*.{js,jsx,vue,ts,tsx}": [
55 | "yarn lint",
56 | "prettier --write",
57 | "git add"
58 | ]
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/service/http.ts:
--------------------------------------------------------------------------------
1 | //http.ts
2 | import axios, { AxiosRequestConfig } from 'axios'
3 | import NProgress from 'nprogress'
4 |
5 | // 设置请求头和请求路径
6 | axios.defaults.baseURL = '/api'
7 | axios.defaults.timeout = 10000
8 | axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
9 | axios.interceptors.request.use(
10 | (config): AxiosRequestConfig