vue中使用tailwindcss

Tailwind CSS with Vue

tailwindcss官方文档

创建Vue项目

sh 复制代码
npm create vite@latest my-project -- --template vue
cd my-project

安装Tailwind CSS,创建tailwind.config.jspostcss.config.js

sh 复制代码
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

配置tailwind.config.js

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

添加Tailwind指令到全局css文件中,此处文件地址比如在./src/style.css

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

main.js入口引入style.css

js 复制代码
import { createApp } from 'vue'
import './style.css'

启动项目

sh 复制代码
npm run dev

在模板中使用tailwindcss

vue 复制代码
<template>
  <h1 class="text-3xl font-bold underline">
    Hello world!
  </h1>
</template>

可以看到页面上此时已经有效果了。

具体使用教程可以查看官方文档。

相关推荐
木斯佳10 小时前
前端八股文面经大全:阿里云AI应用开发二面(2026-03-21)·面经深度解析
前端·css·人工智能·阿里云·ai·面试·vue
工业互联网专业1 天前
基于Python的黑龙江旅游景点数据分析系统的实现_flask+spider
python·flask·vue·毕业设计·源码·课程设计·spider
大叔_爱编程1 天前
基于协同过滤算法的理财产品推荐系统-flask
python·flask·vue·毕业设计·源码·课程设计·协同过滤
小彭努力中2 天前
193.Vue3 + OpenLayers 实战:圆孔相机模型推算卫星拍摄区域
vue.js·数码相机·vue·openlayers·geojson
小彭努力中2 天前
192.Vue3 + OpenLayers 实战:点击地图 Feature,列表自动滚动定位
vue·webgl·openlayers·geojson·webgis
百锦再2 天前
Vue不是万能的:前后端不分离开发的优势
前端·javascript·vue.js·前端框架·vue
BUG创建者2 天前
openlayers上跟据经纬度画出轨迹
开发语言·javascript·vue·html
ん贤2 天前
首屏优化实践:如何将 Vue3 + Vite 项目的加载速度提升3倍
性能优化·vue·vite
A_nanda2 天前
一款前端PDF插件
前端·学习·pdf·vue
沐硕2 天前
校园招聘系统
spring boot·vue·校园招聘