vue3 + vite 使用tailwindcss

第一步:安装依赖

vite版本较低("vite": "^4.0.0")所以就使用低版本的tailwindcss

javascript 复制代码
 npm install -D tailwindcss@3.4.1 postcss autoprefixer

第二步:配置文件生成

javascript 复制代码
npx tailwindcss init -p

会自动生成两个文件postcss.config.js和tailwindcss.config.js

第三步:配置一下tailwindcss.config.js content

javascript 复制代码
/** @type {import('tailwindcss').Config} */
export default {
  content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
  theme: {
    extend: {},
  },
  plugins: [],
}

根据需求配置

第四步:引入样式

这里我是写到了一个css文件中

javascript 复制代码
@tailwind base;
@tailwind components;
@tailwind utilities;

然后main.ts/js引入css文件

javascript 复制代码
import './assets/style/index.css';

最后测试下效果

javascript 复制代码
<template>
    <div class="home font-bold text-red-500">
        页面模板
    </div>
</template>

结束

相关推荐
王夏奇7 分钟前
python中的__all__ 具体用法
java·前端·python
大家的林语冰1 小时前
《前端周刊》尤大开源 Vite+ 全家桶,前端工业革命启动;尤大爆料 Void 云服务新产品,Vite 进军全栈开发;ECMA 源码映射规范......
前端·javascript·vue.js
jiayong231 小时前
第 8 课:开始引入组合式函数
前端·javascript·学习
田八1 小时前
聊聊AI的发展史,AI的爆发并不是偶然
前端·人工智能·程序员
zhanghongbin011 小时前
AI 采集器:Claude Code、OpenAI、LiteLLM 监控
java·前端·人工智能
IT_陈寒1 小时前
Python的列表推导式里藏了个坑,差点让我加班到凌晨
前端·人工智能·后端
吴声子夜歌2 小时前
ES6——正则的扩展详解
前端·mysql·es6
天***88522 小时前
Edge 浏览器离线绿色增强版+官方安装包,支持win7等系统
前端·edge
漫游的渔夫2 小时前
别再直接 `json.loads` 了!AI 返回的 JSON 坑位指南
前端·人工智能
软件工程师文艺2 小时前
从0到1:Claude Code如何用React构建CLI应用
前端·react.js·前端框架