文章目录
- 一、什么是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 doeiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi utaliquip ex ea commodo consequat. Duis aute irure dolor inreprehenderit in voluptate velit esse cillum dolore eu fugiat nullapariatur. Excepteur sint occaecat cupidatat non proident, sunt inculpa 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 voluptatemaccusantium doloremque laudantium, totam rem aperiam, eaque ipsaquae ab illo inventore veritatis et quasi architecto beatae vitaedicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sitaspernatur aut odit aut fugit, sed quia consequuntur magni doloreseos qui ratione voluptatem sequi nesciunt. Consectetur, adipiscivelit, 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 quiblanditiis praesentium voluptatum deleniti atque corrupti quosdolores et quas molestias excepturi sint occaecati cupiditate nonprovident, similique sunt in culpa qui officia deserunt mollitiaanimi, id est laborum et dolorum fuga. Et harum quidem rerum facilisest et expedita distinctio. Nam libero tempore, cum soluta nobis esteligendi optio cumque nihil impedit quo minus.</p></AccordionContent></AccordionPanel></Accordion></div>
</template><script setup>
</script>
运行起来看下效果:
OK,效果很好,而且移动端也是支持的,完美!
接下来就用你喜欢的方式,尽情创作吧~
都看到这里了,各位帅哥/美女,不管有用没用,都帮忙点个赞呗,谢谢~
- Author
- 吴所畏惧 2024.12.05