vue3+TS项目配置unocss

配置unocss

(1)安装依赖

复制代码
npm i unocss @unocss/preset-uno @unocss/preset-attributify -D
npm install @unocss/transformer-directives

(2)根目录新建uno.config.ts文件

ts 复制代码
import { defineConfig } from "unocss";
import presetAttributify from "unocss/preset-attributify";
import presetWind3 from "unocss/preset-wind3";
import transformDirectives from "@unocss/transformer-directives";

export default defineConfig({
  presets: [presetWind3(), presetAttributify()],
  transformers: [transformDirectives()]
});

(3)修改main.ts

ts 复制代码
// main.ts 引入
import "uno.css";

(4)修改vite.config.ts

ts 复制代码
import { defineConfig } from "vite";
import UnoCss from "unocss/vite";
export default defineConfig({
  plugins: [
    UnoCss()
  ]
});

(5)组件中使用

规则查阅:文档

tsx 复制代码
<template>
  <!-- 1. 属性写法 -->
  <div class="content" text-red>
    1234567890
  </div>
</template>
<script setup lang="ts">
import { useDemoStore } from "@/store/demo";

const store = useDemoStore();
</script>
<style scoped lang="scss">
.content {
  // 2. 指令写法,内置指令
  @apply font-bold w-full h-[500px] flex justify-center items-center;
}
</style>
相关推荐
用户0595401744627 分钟前
把前端内存泄漏排查从2小时压到5分钟,我们把它集成进了CI
前端·css
zhanghaofaowhrql2 天前
为CSDN博客编辑器安装自定义CSS主题,打造个性化写作界面
前端·css·编辑器
aichitang20242 天前
Claude fable 5与GPT5.5模型能力实测
javascript·css·人工智能·ai·html·html5
就叫飞六吧2 天前
F12 控制台日志移植到页面案例
javascript·css·html
Bigger4 天前
对不起!我错怪你了,UnoCSS:一次和 AI 一起排查 DevTools 卡顿的经历
前端·css·人工智能
触底反弹4 天前
🎲 纯 CSS 搞定 3D 旋转立方体?还附赠一个「天坑」解决方案!
前端·css·html
finyouIT4 天前
锚点实现了点击导航平滑滚动到页面指定位置的三种方法
javascript·css
用户059540174464 天前
用了半年 LangChain Memory,才发现记忆总“串台”——3 个自动化测试避坑指南
前端·css
More more4 天前
纯手搓css样式:科技感弹窗边框
css·科技·css3
kidding7235 天前
旋转大转盘小程序
前端·css·微信小程序·小程序·前端框架