vite配置-设置路径别名
相对路径别名配置,使用 @ 代替 src
# 一、安装 @types/node
import path from 'path'时,vscode 会出现波浪线,编译时会报错:TS2307: Cannot find module 'path' or its corresponding type declarations.
安装 @types/node 即可
pnpm i @types/node -D |
相对路径别名配置,使用 @ 代替 src
import path from 'path'时,vscode 会出现波浪线,编译时会报错:TS2307: Cannot find module 'path' or its corresponding type declarations.
安装 @types/node 即可
pnpm i @types/node -D |
vue-router4x 相对于 vue-router3x 除了新增了组合式 API 以外,还删除或变动了不少地方。
单独列出来变动点太杂乱。这里系统性的把项目中经常能用到的知识点进行整理.
import { createRouter, createWebHistory } from 'vue-router'; | |
import pinia from './pinia'; | |
import { useUserStore } from '../store/user'; | |
const user = useUserStore(pinia); | |
// 不需要权限的页面 | |
const constantRoutes = [ | |
{ | |
// 登录 | |
path: '/login', | |
name: 'login', | |
component: () => import('../views/login/index.vue') | |
}, | |
{ | |
// 404 | |
path: '/:pathMatch(.*)', | |
name: 'notFound', | |
component: () => import('../views/error/notFound.vue') | |
}, | |
{ | |
// 无权限 | |
path: '/noPermission', | |
name: 'noPermission', | |
component: () => import('../views/error/noPermission.vue') | |
} | |
]; | |
const asyncRoutes = { | |
path: '/', | |
name: 'main', | |
component: () => import('../views/mainPage.vue'), | |
children: [ | |
{ | |
// 首页 | |
path: '/', | |
name: 'home', | |
component: () => import('../views/home/index.vue') | |
}, | |
{ | |
// 用户管理 | |
path: '/settingUser', | |
name: 'settingUser', | |
component: () => import('../views/setting/user.vue') | |
} | |
] | |
}; | |
const router = createRouter({ | |
history: createWebHistory('/'), | |
routes: constantRoutes | |
}); | |
router.addRoute(asyncRoutes); | |
router.beforeEach((to, from, next) => { | |
// 切换 router 时,取消 pending 中的请求 | |
if (window.__axiosPromiseArr) { | |
window.__axiosPromiseArr.forEach((ele, ind) => { | |
ele.cancel(); | |
delete window.__axiosPromiseArr[ind]; | |
}); | |
} | |
//token 过期 | |
if (localStorage.getItem('expires') && (new Date().getTime() - localStorage.getItem('expires')) / 1000 > 1) { | |
this.$message.error('登录失效,请重新登录', () => { | |
localStorage.removeItem('userInfon'); | |
localStorage.removeItem('token'); | |
localStorage.removeItem('expires'); | |
location.href = '/login'; | |
}); | |
return; | |
} | |
// 登录判断 | |
if (user.token) { | |
if (to.path === '/login') { | |
next({ path: '/' }); | |
} else { | |
// 权限判断 | |
next(); | |
} | |
} else { | |
if (to.path === '/login') { | |
next(); | |
} else { | |
next({ name: 'login' }); | |
} | |
} | |
}); | |
// 跳转完成后,将滚动条位置重置 | |
router.afterEach(to => { | |
window.scrollTo(0, 0); | |
}); | |
export default router; |
// 声明 window 上自定义属性,如事件总线 | |
declare interface Window { | |
eventBus: any; | |
} | |
// 声明.vue 文件 | |
declare module "*.vue" { | |
import { DefineComponent } from "vue"; | |
const component: DefineComponent<object, object, any>; | |
export default component; | |
} |
提示:遇到 ts 报错,有些时候是配置未生效,可以重启 vscode 或 ts 服务(vscode 快捷键 ctrl+shift+p 调出命令行,输入 Restart TS Server)
-webkit-background-clip:text; 和 background-clip:text; 是关键属性,将背景只应用到文本的形状上。注意:把当前元素设置为行内块,以便能够应用背景HTML<div class="text-gradient">这是一段测试文字</div> |
CSS.text-gradient { | |
/* 设置字体透明 */ | |
color: transparent; | |
/* 设置线性渐变,从红色渐变到蓝色 */ | |
background-image: linear-gradient(45deg, blue, red); | |
/* 使用 -webkit-background-clip 属性将背景剪裁至文本形状 */ | |
-webkit-background-clip: text; | |
/* 非 Webkit 内核浏览器需要使用标准前缀 */ | |
background-clip: text; | |
/* 把当前元素设置为行内块,以便能够应用背景 */ | |
display: inline-block; | |
} |
在 UnoCSS 的官网首页,已经为我们展示了它的优点
如上已经说的很全面了,UnoCSS 的设计理念是简洁易用,提供了一套直观和易于记忆的类名,使得开发人员能够快速编写和理解样式代码。它遵循类似于 Tailwind CSS 的风格,使用直观的命名规则来描述样式的作用。而且 Antfu 大佬也是 Tailwind 的作者之一。