vue3项目中使用UnoCSS
1. 相关文档:
unocss github 地址
unocss 官网地址
unocss 官网中文版
unocss 交互式文档-可快速查阅缩写
2. 安装并引入:
以vite为例,其余文档中有步骤。https://unocss.dev/integrations/
- 首先安装unocss依赖包
npm install -D unocss
- 然后在vite.config.js 中配置
import UnoCSS from 'unocss/vite' import { defineConfig } from 'vite' export default defineConfig({ plugins: [UnoCSS()] })
- 在main.js中引入
import "uno.css";
也可以创建单独的配置文件uno.config.js
import { defineConfig } from 'unocss' export default defineConfig({ // ...UnoCSS选项 })
然后在main.js中引入单独的配置文件
import 'virtual:uno.css'
3. 使用:
使用时直接在class中书写属性,或者安装@unocss/preset-attributify
启用属性书写模式在属性中对工具类进行分组。
属性化预设文档
<div h-full text-center flex select-none all:transition-400> <div ma> <div text-5xl fw100 animate-bounce-alt animate-count-infinite animate-duration-1s > UnoCSS </div> <div op30 text-lg fw300 m1>The instant on-demand Atomic CSS engine.</div> <div m2 flex justify-center text-2xl op30 hover="op80"> <a i-carbon-logo-github text-inherit href="https://github.com/unocss/unocss" target="_blank" ></a> </div> </div> </div> <div absolute bottom-5 right-0 left-0 text-center op30 fw300> on-demand · instant · fully customizable </div>
4. 其它:
图标预设:将图标作为单个类使用
指令转换器:支持 @apply、@screen 和 theme() 指令。
更多用法可以查看文档
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程