Vue3如何使用tailwindcss,,,,,,,,,,,,,,css框架tailwindcss在Vue3中如何使用

 1.安装

pnpm install -D tailwindcss@latest postcss@latest autoprefixer@latest

2.将根目录下postcss.config.js换成(.postcssrc.json)文件(个人喜好)

在里面添加

{
  "plugins": {
    "tailwindcss": {},
    "autoprefixer": {},
}
{
  "plugins": {
    "tailwindcss": {},
    "autoprefixer": {},
    "postcss-px-to-viewport-8-plugin": {
      "unitToConvert": "px",
      "viewportWidth": 2100,
      "viewportHeight": 1180,
      "unitPrecision": 5,
      "propList": [
        "*"
      ],
      "viewportUnit": "vw",
      "fontViewportUnit": "vw",
      "selectorBlackList": [
        ".no_change_px"
      ],
      "minPixelValue": 1,
      "mediaQuery": false,
      "replace": true
    }
  }
}

3.根目录下创建tailwind.config.ts文件(把单位转成px,因为我是用的是px转vw插件,没有使用rem单位)

export default {
    darkMode: 'class',
    content: ['./index.html', '!./src/**/__tests__/*', './src/**/*.{vue,ts,tsx}'],
    theme: {
        // 内边距
        padding: Array.from({length: 1000}).reduce((map, _, index) => {
            map[index] = `${index}px`;
            return map;
        }, {}),
        // 外边距
        spacing: Array.from({length: 1000}).reduce((map, _, index) => {
            map[index] = `${index}px`;
            return map;
        }, {}),
        // 圆角
        borderRadius: Array.from({length: 100}).reduce((map, _, index) => {
            map[index] = `${index}px`;
            return map;
        }, {}),
        extend: {
            // 宽度
            width: Array.from({length: 1000}).reduce((map, _, index) => {
                map[index] = `${index}px`;
                return map;
            }, {}),
            // 高度
            height: Array.from({length: 1000}).reduce((map, _, index) => {
                map[index] = `${index}px`;
                return map;
            }, {}),
            // 字体大小
            fontSize: Array.from({length: 100}).reduce((map, _, index) => {
                map[index] = `${index}px`;
                return map;
            }, {}),
            // 行高
            lineHeight: Array.from({length: 1000}).reduce((map, _, index) => {
                map[index] = `${index}px`;
                return map;
            }, {}),
        },
    },
    plugins: []
}

4.在styles/index.scss中引入

@tailwind base;
@tailwind components;
@tailwind utilities;

5.在main.ts中引入样式

import "@/styles/index.scss";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值