• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
技术杨的博客园
希望每一次的努力都能得到自己想要的
博客园    首页    新随笔    联系   管理    订阅  订阅

插件系列 vue2安装tailwindcss

官方网址:https://www.tailwindcss.cn/docs/installation

安装步骤:

  1. 直接安装
  2. 创建文件 tailwindcss.css
  3. main.js全局引入文件 tailwindcss.css
  4. 在项目更目录下执行初始化配置文件指令

第一步:直接安装

 npm install -D tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9

第二步:创建文件 tailwindcss.css, 推荐放到样式文件夹下,比如style/ 或者 assets/ 下面。
在 tailwindcss.css 文件内写入如下内容:

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

 

第四步:在项目更目录的终端,执行如下指令,一定要有 -p
npx tailwindcss init -p
之后会在根目录下面自动创建如下两个文件

postcss.config.js文件内容:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

tailwind.config.js文件内容:

module.exports = {
  purge: [],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
 // 禁用基础样式
corePlugins: {
preflight: false,
}
}

最后,就可以愉快的在组件内使用tailwindcss语法了,下面做一个简单的测试demo。
官方首页就有demo,我们可以直接copy下来看下是否有效:(图片链接自行替换)

   <figure class="md:flex bg-white rounded-xl p-8 md:p-0">
        <img class="w-32 h-32 md:w-48 md:h-auto rounded-l-xl mx-autol" src="../../../assets/logo.jpeg" alt="" width="384" height="512" />
        <div class="pt-6 md:p-8 text-center md:text-left space-y-4">
            <blockquote>
                <p class="text-lg font-semibold">
                    “Tailwind CSS is the only framework that I've seen scale on large teams. It’s easy to customize, adapts to any design,
                    and the build size is tiny.”
                </p>
            </blockquote>
            <figcaption class="font-medium">
                <div class="text-cyan-600">Sarah Dayan</div>
                <div class="text-gray-500">Staff Engineer, Algolia</div>
            </figcaption>
        </div>
    </figure>

效果如下:

posted @ 2023-08-11 17:34  技术杨  阅读(611)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3