欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

web前端-vue结合TailwindCss使用指南-vue-tailwindcss

程序员文章站 2022-03-08 08:04:55
vue结合TailwindCss使用指南vue-cli项目的安装vue create vue-csscd vue-cssyarn add tailwindcss@1.4.6新建 tailwind.css,在 src/assets 新建 css 文件夹,并新建 tailwind.css也可以使用命令touch src/assets/css/tailwind.css再 tailwind.css 文件中,添加如下内容:@tailwind base;@tailwind compone...

vue结合TailwindCss使用指南

vue-cli项目的安装

vue create vue-css
cd vue-css
yarn add tailwindcss@1.4.6

新建 tailwind.css,在 src/assets 新建 css 文件夹,并新建 tailwind.css

  • 也可以使用命令

    touch src/assets/css/tailwind.css
    

tailwind.css 文件中,添加如下内容:

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

main.js引入import “./assets/css/tailwind.css”

import "./assets/css/tailwind.css"
or 
import "@/assets/css/tailwind.css"

创建 Tailwind 配置文件

npx tailwind init
or
npx tailwind init --full

web前端-vue结合TailwindCss使用指南-vue-tailwindcss
web前端-vue结合TailwindCss使用指南-vue-tailwindcss

新建 postcss.config.js 文件

const purgecss = require('@fullhuman/postcss-purgecss')({
    content: [
      './src/**/*.html',
      './src/**/*.vue',
      './src/**/*.jsx',
    ],
 
    // Include any special characters you're using in this regular expression
    defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
  })
 
module.exports = {
    plugins: [
      require('tailwindcss'),
      require('autoprefixer'),
      ...process.env.NODE_ENV === 'production'
      ? [purgecss]
      : []
    ]
  }

启动项目

yarn serve

测试

  • 们直接修改 App.vue 文件,来看看效果

    <template>
      <div class="flex items-center justify-center align-middle">
        <div class="flex h-screen">
          <div class="m-auto">
            <div class="md:flex">
              <div class="md:flex-shrink-0">
                <img
                  class="rounded-lg md:w-56"
                  src="https://images.unsplash.com/photo-1556740738-b6a63e27c4df?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2550&q=80"
                  alt="Woman paying for a purchase"
                />
              </div>
              <div class="mt-4 md:mt-0 md:ml-6">
                <div class="uppercase tracking-wide text-sm text-indigo-600 font-bold">Marketing</div>
                <a
                  href="#"
                  class="block mt-1 text-lg leading-tight font-semibold text-gray-900 hover:underline"
                >Finding customers for your new business</a>
                <p
                  class="mt-2 text-gray-600"
                >Getting a new business off the ground is a lot of hard work. Here are five ideas you can use to find your first customers.</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </template>
     
    <style>
    </style>
    

本文地址:https://blog.csdn.net/itwangyang520/article/details/111083768

相关标签: vuejs vue