uniapp如何引入插件原子类css类似tailwindcss、unocss、windcss
在uniapp中引入原子类CSS可以使用以下步骤:
- 安装原子类CSS库,比如tailwindcss:
npm install tailwindcss
- 在项目的根目录下创建一个
tailwind.config.js文件,并添加以下代码:
module.exports = {
purge: ['./src/**/*.{vue,js,ts,jsx,tsx}'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
这里的purge属性表示需要优化的文件路径,可以根据实际情况进行修改。
- 在
main.js中引入tailwindcss并全局注册:
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
import 'tailwindcss/tailwind.css'
const app = createApp(App)
app.mount('#app')
这里的index.css是你自己的样式文件,可以在其中使用tailwind提供的类名。
- 在组件中使用原子类CSS:
<template>
<div class="bg-gray-100 p-4">
<h1 class="text-2xl font-bold mb-4">Hello World</h1>
<p class="text-gray-700">This is a paragraph.</p>
</div>
</template>
这里的bg-gray-100、text-2xl、font-bold、mb-4、text-gray-700等都是tailwind提供的类名,可以根据需求进行组合使用。
注意:以上步骤适用于使用纯HTML和CSS的uniapp项目,如果使用的是uni-app框架,可以在App.vue中进行全局引入和注册。
原文地址: https://www.cveoy.top/t/topic/bIML 著作权归作者所有。请勿转载和采集!