在Vue中安装TailwindCSS

1.安装 Tailwind CSS

# 使用npm
$	npm install tailwindcss -D
# 使用yarn
$	yarn add tailwindcss -D

2.创建 Tailwind CSS 配置文件

$	npx tailwindcss init

3.配置tailwind.config.js

Since Tailwind no longer uses PurgeCSS under the hood, we’ve renamed the purge option to content to better reflect what it’s for: …
翻译: 由于Tailwind不再在幕后使用PurgeCSS,我们已经重新命名了净化选项内容,以更好地反映它的用途:

// /tailwind.config.js

module.exports = {
  // Tailwind CSS 3.0版本开始, 不再使用purgeCSS进行打包优化. 使用`content`配置项代替原`purge`配置项.
  content: [
    './public/**/*.html',
    './src/**/*.{js,jsx,ts,tsx,vue}',
  ],
  theme: {
    extend: {},
  },
  plugins: []
  // 配置前缀, 防止类名与其他UI框架冲突
  // prefix: 'tw-'
}

4.安装 PostCSS 和 autoprefixer

如果使用npm
$	npm install postcss autoprefixer -D

如果使用yarn
$	yarn add postcss autoprefixer -D

## 创建 PostCSS 配置文件

```js
// 在最外层创建 /postcss.config.js

module.exports = {
  plugins: {
    tailwindcss: { config: './tailwind.config.js' },
    autoprefixer: { config: require('autoprefixer') }
  }
}

5.引入TailWindCSS

  • src/assets 目录下创建 tailwindcss.css
// src/assets/tailwindcss.css

@tailwind base;
@tailwind components;
@tailwind utilities;
  • 然后在 main.js 文件中引入
// /src/main.js
import './assets/tailwindcss.css'

最后测试页面是否能正常使用tailwindcss

<div class="p-3 bg-green-500 text-white">Hello Tailwind CSS</div>

如果正常显示则已经配置成功

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值