feat: 更新相关的依赖和修复一些已知的问题

This commit is contained in:
fonghehe 2022-05-27 16:29:39 +08:00
parent ceff802428
commit 1400bdf15c
17 changed files with 674 additions and 419 deletions

7
.husky/pre-commit Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
[ -n "$CI" ] && exit 0
# Format and submit code according to lintstagedrc.js configuration
npm run lint:lint-staged

View File

@ -24,12 +24,12 @@ cd vue-h5-template
npm install npm install
npm run serve npm run dev
``` ```
<span id="top">目录</span> <span id="top">目录</span>
- √ Vue-cli4 - √ vite
- [√ 配置多环境变量](#env) - [√ 配置多环境变量](#env)
- [√ viewport 适配方案](#viewport) - [√ viewport 适配方案](#viewport)
- [√ nutUI 组件按需加载](#nutUI) - [√ nutUI 组件按需加载](#nutUI)
@ -37,8 +37,9 @@ npm run serve
- [√ Vue-router4](#router) - [√ Vue-router4](#router)
- [√ Axios 封装及接口管理](#axios) - [√ Axios 封装及接口管理](#axios)
- [√ vite.config.ts 基础配置](#base) - [√ vite.config.ts 基础配置](#base)
- [√ ts 支持](#alias) - [√ alias](#alias)
- [√ Eslint+Pettier+stylelint 统一开发规范 ](#pettier) - [√ proxy 跨域](#proxy)
- [√ Eslint+Pettier+stylelint 统一开发规范 ](#lint)
### <span id="env">✅ 配置多环境变量 </span> ### <span id="env">✅ 配置多环境变量 </span>
@ -62,9 +63,7 @@ npm run serve
不用担心,项目已经配置好了 `viewport` 适配, 下面仅做介绍: 不用担心,项目已经配置好了 `viewport` 适配, 下面仅做介绍:
Vant 中的样式默认使用`px`作为单位,如果需要使用`rem`单位,推荐使用以下两个工具: - [postcss-px-to-viewport-8-plugin](https://github.com/xian88888888/postcss-px-to-viewport-8-plugin) 是一款 `postcss` 插件,用于将单位转化为 `vw`, 现在很多浏览器对`vw`的支持都很好。
- [postcss-px-to-viewport-8-plugin](https://github.com/xian88888888/postcss-px-to-viewport-8-plugin) 是一款 `postcss` 插件,用于将单位转化为 `vw`
##### PostCSS 配置 ##### PostCSS 配置
@ -74,9 +73,6 @@ Vant 中的样式默认使用`px`作为单位,如果需要使用`rem`单位,
// https://github.com/michael-ciniawsky/postcss-load-config // https://github.com/michael-ciniawsky/postcss-load-config
module.exports = { module.exports = {
plugins: { plugins: {
autoprefixer: {
overrideBrowserslist: ['Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8'],
},
'postcss-px-to-viewport-8-plugin': { 'postcss-px-to-viewport-8-plugin': {
unitToConvert: 'px', // 要转化的单位 unitToConvert: 'px', // 要转化的单位
viewportWidth: 375, // UI设计稿的宽度 viewportWidth: 375, // UI设计稿的宽度
@ -127,6 +123,7 @@ module.exports = {
width: 750px; width: 750px;
height: 1334px; height: 1334px;
} }
/* rootValue: 37.5 */ /* rootValue: 37.5 */
.image { .image {
width: 375px; width: 375px;
@ -337,7 +334,9 @@ export function getUserInfo(params) {
// 请求接口 // 请求接口
import { getUserInfo } from '@/api/user.js'; import { getUserInfo } from '@/api/user.js';
const params = { user: 'sunnie' }; const params = {
user: 'sunnie',
};
getUserInfo(params) getUserInfo(params)
.then(() => {}) .then(() => {})
.catch(() => {}); .catch(() => {});
@ -397,9 +396,21 @@ export default function ({ command }: ConfigEnv): UserConfigExport {
```javascript ```javascript
resolve: { resolve: {
alias: { alias: [{
'@': pathResolve('./src'), find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
}, },
// /@/xxxx => src/xxxx
{
find: /\/@\//,
replacement: pathResolve('src') + '/',
},
// /#/xxxx => types/xxxx
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
],
}, },
``` ```
@ -421,16 +432,18 @@ server: {
[▲ 回顶部](#top) [▲ 回顶部](#top)
<h3>文档在拼命完善中。。。</h3> ### <span id="lint">✅ Eslint+Pettier+stylelint 统一开发规范 </span>
根目录下的`.eslintrc.js``.stylelint.config.js``.prettier.config.js`内置了 lint 规则,帮助你规范地开发代码,有助于提高团队的代码质量和协作性,可以根据团队的规则进行修改
# 关于我 # 关于我
扫描添加下方的微信并备注加交流群,交流学习,及时获取代码最新动态。
<p> <p>
<img src="./public/account.jpg" width="256" style="display:inline; "> <img src="./public/account.jpg" width="256" style="display:inline; ">
</p> </p>
扫描添加下方的微信并备注加交流群,交流学习,及时获取代码最新动态。
<p> <p>
<img src="./public/group.png" width="256" style="display:inline; "> <img src="./public/group.png" width="256" style="display:inline; ">
</p> </p>

View File

@ -20,48 +20,51 @@
}, },
"dependencies": { "dependencies": {
"@nutui/nutui": "^3.1.20", "@nutui/nutui": "^3.1.20",
"@vueuse/core": "8.3.1", "@vueuse/core": "8.5.0",
"@vueuse/integrations": "8.3.1", "@vueuse/integrations": "8.5.0",
"axios": "0.27.2", "axios": "0.27.2",
"pinia": "^2.0.13", "pinia": "^2.0.14",
"universal-cookie": "^4.0.4", "universal-cookie": "^4.0.4",
"vant": "^3.4.8", "vant": "^3.4.9",
"vue": "^3.2.33", "vue": "^3.2.36",
"vue-i18n": "^9.1.9", "vue-i18n": "^9.1.10",
"vue-router": "^4.0.14" "vue-router": "^4.0.15"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^17.0.29", "@types/node": "^17.0.35",
"@typescript-eslint/eslint-plugin": "^5.21.0", "@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.21.0", "@typescript-eslint/parser": "^5.26.0",
"@vitejs/plugin-legacy": "^1.8.1", "@vitejs/plugin-legacy": "^1.8.2",
"@vitejs/plugin-vue": "^2.3.1", "@vitejs/plugin-vue": "^2.3.3",
"@vitejs/plugin-vue-jsx": "^1.3.10", "@vitejs/plugin-vue-jsx": "^1.3.10",
"consola": "^2.15.3", "consola": "^2.15.3",
"eruda": "^2.4.1", "eruda": "^2.4.1",
"eslint": "^8.14.0", "eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.7.1", "eslint-plugin-vue": "^9.0.1",
"husky": "7.0.4", "husky": "7.0.4",
"lint-staged": "12.4.1", "lint-staged": "12.4.1",
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
"postcss": "^8.4.12", "postcss": "^8.4.14",
"postcss-px-to-viewport-8-plugin": "^1.1.3", "postcss-px-to-viewport-8-plugin": "^1.1.3",
"postcss-html": "^1.4.1",
"postcss-less": "^6.0.0",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"stylelint": "^14.8.0", "stylelint": "^14.8.5",
"stylelint-config-prettier": "^9.0.3", "stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^7.0.0", "stylelint-config-recommended": "^7.0.0",
"stylelint-config-recommended-vue": "^1.4.0", "stylelint-config-recommended-vue": "^1.4.0",
"stylelint-config-standard": "^25.0.0", "stylelint-config-standard": "^25.0.0",
"stylelint-order": "^5.0.0", "stylelint-order": "^5.0.0",
"typescript": "^4.6.3", "typescript": "^4.7.2",
"vite": "^2.9.6", "vite": "^2.9.9",
"vite-plugin-eruda": "^1.0.1", "vite-plugin-eruda": "^1.0.1",
"vite-plugin-mock": "^2.9.6", "vite-plugin-mock": "^2.9.6",
"vite-plugin-style-import": "^2.0.0", "vite-plugin-style-import": "^2.0.0",
"vue-eslint-parser": "^8.3.0", "vue-eslint-parser": "^9.0.2",
"vue-tsc": "^0.34.10" "vue-tsc": "^0.34.16",
"yorkie": "^2.0.0"
}, },
"lint-staged": { "lint-staged": {
"*.{js,jsx,ts,tsx}": [ "*.{js,jsx,ts,tsx}": [

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 362 KiB

View File

@ -1,4 +1,4 @@
import useAxiosApi from '@/utils/useAxiosApi'; import useAxiosApi from '/@/utils/useAxiosApi';
/** /**
* *

View File

@ -1,3 +1,4 @@
import { AnyObject } from '#/global';
import { createI18n } from 'vue-i18n'; import { createI18n } from 'vue-i18n';
export function loadLang() { export function loadLang() {

View File

@ -1,9 +1,9 @@
import { createApp } from 'vue'; import { createApp } from 'vue';
import App from './App.vue'; import App from './App.vue';
import { nutUiComponents } from './plugins/nutUI'; import { nutUiComponents } from './plugins/nutUI';
import { i18n } from '@/i18n'; import { i18n } from '/@/i18n';
import router from './router'; import router from './router';
import { setupStore } from '@/store'; import { setupStore } from '/@/store';
import './assets/font/iconfont.css'; import './assets/font/iconfont.css';
import './assets/app.css'; import './assets/app.css';

View File

@ -1,12 +1,12 @@
import { createRouter, createWebHistory, Router } from 'vue-router'; import { createRouter, createWebHashHistory, Router } from 'vue-router';
import routes from './routes'; import routes from './routes';
const router: Router = createRouter({ const router: Router = createRouter({
history: createWebHistory(), history: createWebHashHistory('/'),
routes: routes, routes: routes,
}); });
router.beforeEach(async (to, from, next) => { router.beforeEach(async (_to, _from, next) => {
next(); next();
}); });

View File

@ -3,12 +3,12 @@ const routes = [
name: 'root', name: 'root',
path: '/', path: '/',
redirect: '/home', redirect: '/home',
component: () => import('@/components/Basic/index.vue'), component: () => import('/@/components/Basic/index.vue'),
children: [ children: [
{ {
name: 'Home', name: 'Home',
path: 'home', path: 'home',
component: () => import('@/views/Home/index.vue'), component: () => import('/@/views/Home/index.vue'),
meta: { meta: {
title: '', title: '',
keepAlive: true, keepAlive: true,
@ -17,7 +17,7 @@ const routes = [
{ {
name: 'List', name: 'List',
path: 'list', path: 'list',
component: () => import('@/views/List/index.vue'), component: () => import('/@/views/List/index.vue'),
meta: { meta: {
title: '', title: '',
keepAlive: true, keepAlive: true,
@ -26,7 +26,7 @@ const routes = [
{ {
name: 'Member', name: 'Member',
path: 'member', path: 'member',
component: () => import('@/views/Member/index.vue'), component: () => import('/@/views/Member/index.vue'),
meta: { meta: {
title: '', title: '',
keepAlive: true, keepAlive: true,
@ -37,7 +37,7 @@ const routes = [
{ {
name: 'Login', name: 'Login',
path: '/login', path: '/login',
component: () => import('@/views/Login/index.vue'), component: () => import('/@/views/Login/index.vue'),
meta: { meta: {
title: '', title: '',
keepAlive: true, keepAlive: true,

View File

@ -1,4 +1,5 @@
import { loginPassword } from '@/api'; import { AnyObject } from '/#/global';
import { loginPassword } from '/@/api';
import { useCookies } from '@vueuse/integrations/useCookies'; import { useCookies } from '@vueuse/integrations/useCookies';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { watch } from 'vue'; import { watch } from 'vue';

View File

@ -1,6 +1,4 @@
/** import { AnyObject } from '#/global';
*
*/
export function typeCheck(param: any) { export function typeCheck(param: any) {
return Object.prototype.toString.call(param); return Object.prototype.toString.call(param);

View File

@ -30,8 +30,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'; import { computed } from 'vue';
import { useUserStore } from '@/store/modules/user'; import { useUserStore } from '/@/store/modules/user';
import { setLang } from '@/i18n'; import { setLang } from '/@/i18n';
const userStore = useUserStore(); const userStore = useUserStore();
const getUserInfo = computed(() => { const getUserInfo = computed(() => {

View File

@ -14,9 +14,9 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import router from '@/router'; import { router } from '/@/router';
import { ComponentInternalInstance, getCurrentInstance, reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { useUserStore } from '@/store/modules/user'; import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore(); const userStore = useUserStore();
const formData = reactive({ const formData = reactive({
@ -24,7 +24,7 @@
pwd: '', pwd: '',
}); });
const ruleForm = ref<any>(null); const ruleForm = ref<any>(null);
const { proxy } = getCurrentInstance() as ComponentInternalInstance; // const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const submit = () => { const submit = () => {
ruleForm.value.validate().then(async ({ valid, errors }: any) => { ruleForm.value.validate().then(async ({ valid, errors }: any) => {
if (valid) { if (valid) {

View File

@ -23,8 +23,8 @@
"types": ["vite/client"], "types": ["vite/client"],
"removeComments": true, "removeComments": true,
"paths": { "paths": {
"@/*": ["src/*"], "/@/*": ["src/*"],
"#/*": ["types/*"] "/#/*": ["types/*"]
} }
}, },
"include": [ "include": [

2
types/global.d.ts vendored
View File

@ -87,7 +87,7 @@ declare global {
} }
} }
interface AnyObject { export interface AnyObject {
[key: string]: any; [key: string]: any;
} }

View File

@ -6,13 +6,35 @@ import { createStyleImportPlugin, NutuiResolve } from 'vite-plugin-style-import'
import { viteMockServe } from 'vite-plugin-mock'; import { viteMockServe } from 'vite-plugin-mock';
import eruda from 'vite-plugin-eruda'; import eruda from 'vite-plugin-eruda';
const pathResolve = (dir: string) => resolve(__dirname, dir); const pathResolve = (dir: string) => {
return resolve(process.cwd(), '.', dir);
};
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default function ({ command }: ConfigEnv): UserConfigExport { export default function ({ command }: ConfigEnv): UserConfigExport {
const isProduction = command === 'build'; const isProduction = command === 'build';
const root = process.cwd();
console.log(isProduction); console.log(isProduction);
return { return {
root,
resolve: {
alias: [
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
},
// /@/xxxx => src/xxxx
{
find: /\/@\//,
replacement: pathResolve('src') + '/',
},
// /#/xxxx => types/xxxx
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
],
},
server: { server: {
host: '0.0.0.0', host: '0.0.0.0',
}, },
@ -37,10 +59,5 @@ export default function ({ command }: ConfigEnv): UserConfigExport {
}, },
}, },
}, },
resolve: {
alias: {
'@': pathResolve('./src'),
},
},
}; };
} }

861
yarn.lock

File diff suppressed because it is too large Load Diff