文章目录
- 一、什么是PrimeVue
- 二、详细教程
- 1.添加PrimeVue
- 2.配置main.js
- 3.添加自动引入
- 4.配置vite.config.js
- 5.创建测试页面
一、什么是PrimeVue
PrimeVue 是一个用于 Vue.js 3.x 开发的一款高质量、广受欢迎的 Web UI 组件库。
官网地址:https://primevue.org/
二、详细教程
我这里是通过
vite
安装的
至于怎么用vite
搭建vue3
项目及其初始化的教程,详请看我上一篇文章:
一文教你用vite创建vue3项目初始化并添加router、axios、Pinia保姆级教程
这里就直接开始搞命令:
1.添加PrimeVue
pnpm add primevue @primevue/themes
2.配置main.js
import { createApp } from "vue";
import App from "./App.vue";
import PrimeVue from "primevue/config";
import Aura from "@primevue/themes/aura";
const app = createApp(App);
app.use(PrimeVue, {
theme: {
preset: Aura,
},
});
app.mount("#app");
3.添加自动引入
pnpm i unplugin-vue-components -D
pnpm i @primevue/auto-import-resolver -D
4.配置vite.config.js
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { PrimeVueResolver } from "@primevue/auto-import-resolver";
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [PrimeVueResolver()],
}),
]
});
5.创建测试页面
我们将 前面根据教程初始化好的
index.vue
页面的代码改为:
<template>
<div class="card">
<Accordion value="0">
<AccordionPanel value="0">
<AccordionHeader>Header I</AccordionHeader>
<AccordionContent>
<p class="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
</AccordionContent>
</AccordionPanel>
<AccordionPanel value="1">
<AccordionHeader>Header II</AccordionHeader>
<AccordionContent>
<p class="m-0">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa
quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit
aspernatur aut odit aut fugit, sed quia consequuntur magni dolores
eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci
velit, sed quia non numquam eius modi.
</p>
</AccordionContent>
</AccordionPanel>
<AccordionPanel value="2">
<AccordionHeader>Header III</AccordionHeader>
<AccordionContent>
<p class="m-0">
At vero eos et accusamus et iusto odio dignissimos ducimus qui
blanditiis praesentium voluptatum deleniti atque corrupti quos
dolores et quas molestias excepturi sint occaecati cupiditate non
provident, similique sunt in culpa qui officia deserunt mollitia
animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis
est et expedita distinctio. Nam libero tempore, cum soluta nobis est
eligendi optio cumque nihil impedit quo minus.
</p>
</AccordionContent>
</AccordionPanel>
</Accordion>
</div>
</template>
<script setup>
</script>
运行起来看下效果:
OK,效果很好,而且移动端也是支持的,完美!
接下来就用你喜欢的方式,尽情创作吧~
都看到这里了,各位帅哥/美女,不管有用没用,都帮忙点个赞呗,谢谢~
-
Author
- 吴所畏惧 2024.12.05