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>

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

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

相关推荐
万亿少女的梦16816 小时前
基于Python的高考志愿填报辅助系统设计与实现
java·spring boot·python·mysql·vue
万亿少女的梦16816 小时前
基于SpringBoot与Vue的历史博物馆展品展示与游客管理系统设计
spring boot·mysql·vue·系统设计·博物馆管理系统
衍生星球17 小时前
SpringBoot3 + Vue3 + 微信小程序如何学习,以及学哪些技术,组件
sql·微信小程序·uni-app·vue·springboot
志尊宝1 天前
Vue3 环境搭建 + 第一个 HelloVue 项目(零基础入门)
vue.js·node.js·vue·css3
万亿少女的梦1681 天前
基于Spring Boot与Vue的繁星技术论坛系统设计与实现
java·spring boot·mysql·vue·系统设计
随心(cracker)2 天前
BeaverX Admin:一套真正能跑起来的开源管理后台
vue·.net·管理后台
万亿少女的梦1682 天前
基于SpringBoot的考研学习交流系统设计与开发
spring boot·mysql·vue·系统设计·论坛系统
格子软件3 天前
2026年GEO贴牌代理:分布式多级分账状态机源码深度解构
java·vue.js·分布式·vue·geo
程序员 Harry3 天前
AriesMusic Free Music
vue
格子软件3 天前
2026年分布式GEO代理流量调度:源码级状态机防重挂实战
java·vue.js·人工智能·spring boot·分布式·vue