Vue3 PrimeVue 应用开发实战1 vue3.0开发
suiw9 2024-10-28 18:28 22 浏览 0 评论
Vue3 PrimeVue 应用开发实战1
1.PrimeVue简介
PrimeVue 是一套非常优秀的 Vue UI 组件库,支持 Vue 3 的 web UI 组件库,组件丰富,定制性很强,官网文档清晰,代码例子充足,而且中文化也做得很不错,是一款可用性很强的 Vue 组件库。
PrimeVue 的技术特性:
- 组件丰富。内置 70 多个常用的组件,体验优秀,使用简单
- 主题丰富。内置大量主题,且提供强大的主题定制工具
- 高效开发模板。由专业设计师设计并由 Vue 专家精心制作的精致的 Vue-CLI 开发模板
- 可访问性强。面向所有人的UI组件,全面支持 WCAG(Web内容可访问性指南)标准
- PrimeVue 是一个与设计无关的库,实现原理是将样式分为 core 和 theme。core 驻留在 PrimeVue 内部,以实现和组件结构相关的效果,例如定位,而 theme 实现颜色,填充和边距。
- PrimeVue 提供各种免费开源的主题和高级主题,我们可以从各种主题中进行选择,也可以使用官方提供 Theme Designer 工具轻松开发自己的主题。
PrimeVue文档:
英文文档:https://primefaces.org/primevue
中文文档:http://www.primevue.top
中文文档和英文文档版本不一致,建议以英文文档为主,参照中文文档,如果英文好的话就只看英文文档。
2.使用PrimeVue
使用PrimeVue,需要使用的主要内容包括:组件、图标、布局系统,所以,需要安装这三个部分,命令如下:
npm install primevue@^3.12.1 --save
npm install primeicons --save
npm install primeflex --save
下一步,设置PrimeVue配置:
import {createApp} from 'vue';
import App from './App.vue';
import PrimeVue from 'primevue/config';
const app = createApp(App);
app.use(PrimeVue);
接下来,导入样式单
primevue/resources/themes/saga-blue/theme.css //theme
primevue/resources/primevue.min.css //core css
primeicons/primeicons.css //icons
如果需要使用布局系统,还需要导入:
primeflex/primeflex.css
main.js文件完整内容:
import { createApp } from 'vue'
import App from './institution.vue'
import PrimeVue from 'primevue/config'
import 'primevue/resources/themes/bootstrap4-light-blue/theme.css' //theme
import 'primevue/resources/primevue.min.css' //core css
import 'primeicons/primeicons.css' //icons
import 'primeflex/primeflex.scss'
const app = createApp(App)
app.use(PrimeVue)
app.mount('#app')
3.主题
PrimeVue提供了一些免费的主题供用户使用,如下:
primevue/resources/themes/bootstrap4-light-blue/theme.css
primevue/resources/themes/bootstrap4-light-purple/theme.css
primevue/resources/themes/bootstrap4-dark-blue/theme.css
primevue/resources/themes/bootstrap4-dark-purple/theme.css
primevue/resources/themes/md-light-indigo/theme.css
primevue/resources/themes/md-light-deeppurple/theme.css
primevue/resources/themes/md-dark-indigo/theme.css
primevue/resources/themes/md-dark-deeppurple/theme.css
primevue/resources/themes/mdc-light-indigo/theme.css
primevue/resources/themes/mdc-light-deeppurple/theme.css
primevue/resources/themes/mdc-dark-indigo/theme.css
primevue/resources/themes/mdc-dark-deeppurple/theme.css
primevue/resources/themes/tailwind-light/theme.css
primevue/resources/themes/fluent-light/theme.css
primevue/resources/themes/lara-light-indigo/theme.css
primevue/resources/themes/lara-dark-indigo/theme.css
primevue/resources/themes/lara-light-purple/theme.css
primevue/resources/themes/lara-dark-purple/theme.css
primevue/resources/themes/lara-light-blue/theme.css
primevue/resources/themes/lara-dark-blue/theme.css
primevue/resources/themes/lara-light-teal/theme.css
primevue/resources/themes/lara-dark-teal/theme.css
primevue/resources/themes/saga-blue/theme.css
primevue/resources/themes/saga-green/theme.css
primevue/resources/themes/saga-orange/theme.css
primevue/resources/themes/saga-purple/theme.css
primevue/resources/themes/vela-blue/theme.css
primevue/resources/themes/vela-green/theme.css
primevue/resources/themes/vela-orange/theme.css
primevue/resources/themes/vela-purple/theme.css
primevue/resources/themes/arya-blue/theme.css
primevue/resources/themes/arya-green/theme.css
primevue/resources/themes/arya-orange/theme.css
primevue/resources/themes/arya-purple/theme.css
primevue/resources/themes/nova/theme.css
primevue/resources/themes/nova-alt/theme.css
primevue/resources/themes/nova-accent/theme.css
primevue/resources/themes/nova-vue/theme.css
primevue/resources/themes/luna-amber/theme.css
primevue/resources/themes/luna-blue/theme.css
primevue/resources/themes/luna-green/theme.css
primevue/resources/themes/luna-pink/theme.css
primevue/resources/themes/rhea/theme.css
我们可以根据自己的需要直接导入使用。
4.使用组件
按需导入:需要什么组件导入什么组件,可以在main.js文件中导入后全局注册,也可以在需要使用的组件中导入后局部注册。
如,局部注册如下:
<template>
......
<Dialog></Dialog>
......
</template>
<script>
import Dialog from 'primevue/dialog'
......
export default {
......
components: {
Dialog
}
......
}
</script>
5.开发实战
实战案例:实现一个子页面框架。
所谓子页面是指在单页面开发中路由显示的页面,即<router-view/>中显示的内容,或者是多页面开发中在<div></div>或<iframe/>中显示的页面。为了统一风格,我们在实际开发中需要对子页面进行一些规范,比如划分区域,视窗大小等。
本节案例的子页面按照后台管理系统的要求进行设计,即:
子页面区域包括:
- 外边框 - 指页面外边框。
- 标题栏 - 左侧显示标题,个别情况下右侧显示操作按钮或者提示信息等。
- 查询栏 - 用于查询数据设置条件,及页面包含的操作,如增删改等。
- 数据栏 - 用于显示数据,一般是表格。
- 表单对话框 - 用于在数据增加、修改时填写表单。
整个子页面设计中,可以固定高度的只有标题栏,其他都有可能随着操作数据的不同而不同,所以外边框应该是100%充满显示区域,查询栏根据查询内容的多少及操作按钮的多少动态调整,剩余的空间都给数据栏,所以数据栏需要滚动条,如果数据栏中是表格的话,数据在表格中上下滚动。
根据以上需求,各部分设计及样式单分别如下:
5.1 外边框
<div style="height: 100vh; padding: 6px;">
</div>
5.2标题栏
标题栏直接使用PrimeVue的Toolbar即可,代码如下:
<Toolbar style="padding: 12px;">
<template #start>
<i class="pi pi-bars p-toolbar-separator mr-2" />
<Tag value="标题"></Tag>
</template>
<template #end>
<Button icon="pi pi-search" class="mr-2" />
<Button icon="pi pi-calendar" class="p-button-success mr-2" />
<Button icon="pi pi-times" class="p-button-danger" />
</template>
</Toolbar>
5.3查询栏
<div class="query-box">
<div class="grid">
<div class="col-3">
<div class="query-field-title">查询字段</div>
<InputText type="text"/>
</div>
<div class="col-9" style="padding-top: 15px;">
<Button type="button" label="查询" icon="pi pi-search" style="margin-right: 12px;"/>
<Button type="button" label="全部" icon="pi pi-search" style="margin-right: 12px;"/>
<Button type="button" label="新建" icon="pi pi-plus" style="margin-right: 12px;"/>
<Button type="button" label="编辑" icon="pi pi-pencil" style="margin-right: 12px;"/>
<Button type="button" label="删除" icon="pi pi-times" style="margin-right: 12px;"/>
</div>
</div>
</div>
查询栏内部使用了PrimeFlex的Grid布局,此Grid布局总宽度为12列,当大于12列后会自动换行,根据实际需要进行调整即可,比如本例只用了一行,左侧为查询字段,右侧为操作按钮,所以class分别是:col-3和col-9,在查询字段的单元格中,内容为:
<div class="query-field-title">查询字段</div>
<InputText type="text" v-model="kw"/>
显示效果如下:
查询栏外边框的样式类 query-box,代码如下:
.query-box {
margin-left: 1px;
margin-right: 1px;
margin-top: 12px;
background: #ffffff;
border-radius: 6px;
padding-top: 12px;
padding-left: 12px;
padding-right: 12px;
padding-bottom: 0px;
box-shadow: #999999 0px 0px 6px;
}
查询字段标题的样式类 query-field-title,代码如下:
.query-field-title {
font-size: 10px;
padding-bottom: 6px;
color: #999999;
}
5.4数据栏
数据栏中一般是表格,所以在此,我们只设计一个外边框,代码如下:
<div class="table-box" style="height: calc(100% - 156px);">
</div>
这里,动态高度通过css来设置,代码:
height: calc(100% - 156px);
156px需要在实际开发中手工计算。
外边框样式类 table-box 代码:
.table-box {
margin-left: 1px;
margin-right: 1px;
margin-top: 12px;
background: #ffffff;
border-radius: 6px;
padding-top: 12px;
padding-left: 12px;
padding-right: 12px;
padding-bottom: 0px;
box-shadow: #999999 0px 0px 6px;
}
5.5表单对话框
表单对话框直接用PrimeVue的Dialog组件来实现,代码如下:
<Dialog v-model:visible="dialogVisible" :modal="true" :draggable="true" style="width: 600px;">
<template #header>
<Tag value="表单标题" icon="pi pi-list"></Tag>
</template>
<div class="form-box">
<div class="grid">
<div class="col-2 form-field-title">表单字段</div>
<div class="col-10">
......
</div>
<div class="col-2 form-field-title">表单字段</div>
<div class="col-10">
......
</div>
......
</div>
</div>
<template #footer>
<Button label="取消" icon="pi pi-times" class="p-button-text" />
<Button label="确定" icon="pi pi-check" autofocus />
</template>
</Dialog>
在对话框中,使用了 PrimeFlex的 Grid 来布局字段与输入组件,这样做,比较灵活可控,可以根据自己的需要进行编排字段和控件的布局,比如使用单列式,多列式等。
对话框中 Grid 外边框样式类 form-box 代码:
.form-box {
border: 1px solid #E9EDF1;
background: #f8f9fa;
padding-top: 8px;
padding-left: 12px;
padding-right: 12px;
border-radius: 6px;
box-shadow: #999999 0px 0px 6px;
}
对话框中表单字段标题样式类 form-field-title 代码:
.form-field-title {
color: #999999;
}
6.整体代码及效果
示例代码如下:
<template>
<!--外边框-->
<div style="height: 100vh; padding: 6px;">
<!--标题栏-->
<Toolbar style="padding: 12px;">
<template #start>
<i class="pi pi-bars p-toolbar-separator mr-2" />
<Tag value="标题"></Tag>
</template>
<template #end>
<Button icon="pi pi-search" class="p-button-sm" style="margin-right: 6px;"/>
<Button icon="pi pi-calendar" class="p-button-success p-button-sm" style="margin-right: 6px;"/>
<Button icon="pi pi-times" class="p-button-danger p-button-sm" />
</template>
</Toolbar>
<!--查询栏-->
<div class="query-box">
<div class="grid">
<div class="col-3">
<div class="query-field-title">查询字段</div>
<InputText type="text"/>
</div>
<div class="col-9" style="padding-top: 15px;">
<Button type="button" label="查询" icon="pi pi-search" style="margin-right: 12px;"/>
<Button type="button" label="全部" icon="pi pi-search" style="margin-right: 12px;"/>
<Button type="button" label="新建" icon="pi pi-plus" style="margin-right: 12px;" @click="dialogVisible = true"/>
<Button type="button" label="编辑" icon="pi pi-pencil" style="margin-right: 12px;"/>
<Button type="button" label="删除" icon="pi pi-times" style="margin-right: 12px;"/>
</div>
</div>
</div>
<!--数据栏-->
<div class="table-box" style="height: calc(100% - 156px);">
</div>
</div>
<!--表单对话框-->
<Dialog v-model:visible="dialogVisible" :modal="true" :draggable="true" style="width: 600px;">
<template #header>
<Tag value="表单标题" icon="pi pi-list"></Tag>
</template>
<div class="form-box">
<div class="grid">
<div class="col-2 form-field-title">表单字段1</div>
<div class="col-10">
<InputText type="text"/>
</div>
<div class="col-2 form-field-title">表单字段2</div>
<div class="col-10">
<InputText type="text"/>
</div>
</div>
</div>
<template #footer>
<Button label="取消" icon="pi pi-times" class="p-button-text" @click="dialogVisible = false"/>
<Button label="确定" icon="pi pi-check" autofocus />
</template>
</Dialog>
</template>
<script>
import Toolbar from 'primevue/toolbar'
import Tag from 'primevue/tag'
import Button from 'primevue/button'
import InputText from 'primevue/inputtext'
import Dialog from 'primevue/dialog'
export default {
name: "UserManage",
components: {
Toolbar,
Tag,
Button,
InputText,
Dialog
},
data () {
return {
dialogVisible: false
}
}
}
</script>
<style scoped>
@import "../../assets/css/sub_frame.css";
</style>
页面效果:
表单效果:
相关推荐
- 俄罗斯的 HTTPS 也要被废了?(俄罗斯网站关闭)
-
发布该推文的ScottHelme是一名黑客,SecurityHeaders和ReportUri的创始人、Pluralsight作者、BBC常驻黑客。他表示,CAs现在似乎正在停止为俄罗斯域名颁发...
- 如何强制所有流量使用 HTTPS一网上用户
-
如何强制所有流量使用HTTPS一网上用户使用.htaccess强制流量到https的最常见方法可能是使用.htaccess重定向请求。.htaccess是一个简单的文本文件,简称为“.h...
- https和http的区别(https和http有何区别)
-
“HTTPS和HTTP都是数据传输的应用层协议,区别在于HTTPS比HTTP安全”。区别在哪里,我们接着往下看:...
- 快码住!带你十分钟搞懂HTTP与HTTPS协议及请求的区别
-
什么是协议?网络协议是计算机之间为了实现网络通信从而达成的一种“约定”或“规则”,正是因为这个“规则”的存在,不同厂商的生产设备、及不同操作系统组成的计算机之间,才可以实现通信。简单来说,计算机与网络...
- 简述HTTPS工作原理(简述https原理,以及与http的区别)
-
https是在http协议的基础上加了一层SSL(由网景公司开发),加密由ssl实现,它的目的是为用户提供对网站服务器的身份认证(需要CA),以至于保护交换数据的隐私和完整性,原理如图示。1、客户端发...
- 21、HTTPS 有几次握手和挥手?HTTPS 的原理什么是(高薪 常问)
-
HTTPS是3次握手和4次挥手,和HTTP是一样的。HTTPS的原理...
- 一次安全可靠的通信——HTTPS原理
-
为什么HTTPS协议就比HTTP安全呢?一次安全可靠的通信应该包含什么东西呢,这篇文章我会尝试讲清楚这些细节。Alice与Bob的通信...
- 为什么有的网站没有使用https(为什么有的网站点不开)
-
有的网站没有使用HTTPS的原因可能涉及多个方面,以下是.com、.top域名的一些见解:服务器性能限制:HTTPS使用公钥加密和私钥解密技术,这要求服务器具备足够的计算能力来处理加解密操作。如果服务...
- HTTPS是什么?加密原理和证书。SSL/TLS握手过程
-
秘钥的产生过程非对称加密...
- 图解HTTPS「转」(图解http 完整版 彩色版 pdf)
-
我们都知道HTTPS能够加密信息,以免敏感信息被第三方获取。所以很多银行网站或电子邮箱等等安全级别较高的服务都会采用HTTPS协议。...
- HTTP 和 HTTPS 有何不同?一文带你全面了解
-
随着互联网时代的高速发展,Web服务器和客户端之间的安全通信需求也越来越高。HTTP和HTTPS是两种广泛使用的Web通信协议。本文将介绍HTTP和HTTPS的区别,并探讨为什么HTTPS已成为We...
- HTTP与HTTPS的区别,详细介绍(http与https有什么区别)
-
HTTP与HTTPS介绍超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息,HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了Web浏览器和网站服务器之间的...
- 一文让你轻松掌握 HTTPS(https详解)
-
一文让你轻松掌握HTTPS原文作者:UC国际研发泽原写在最前:欢迎你来到“UC国际技术”公众号,我们将为大家提供与客户端、服务端、算法、测试、数据、前端等相关的高质量技术文章,不限于原创与翻译。...
- 如何在Spring Boot应用程序上启用HTTPS?
-
HTTPS是HTTP的安全版本,旨在提供传输层安全性(TLS)[安全套接字层(SSL)的后继产品],这是地址栏中的挂锁图标,用于在Web服务器和浏览器之间建立加密连接。HTTPS加密每个数据包以安全方...
- 一文彻底搞明白Http以及Https(http0)
-
早期以信息发布为主的Web1.0时代,HTTP已可以满足绝大部分需要。证书费用、服务器的计算资源都比较昂贵,作为HTTP安全扩展的HTTPS,通常只应用在登录、交易等少数环境中。但随着越来越多的重要...
你 发表评论:
欢迎- 一周热门
-
-
Linux:Ubuntu22.04上安装python3.11,简单易上手
-
宝马阿布达比分公司推出独特M4升级套件,整套升级约在20万
-
MATLAB中图片保存的五种方法(一)(matlab中保存图片命令)
-
别再傻傻搞不清楚Workstation Player和Workstation Pro的区别了
-
Linux上使用tinyproxy快速搭建HTTP/HTTPS代理器
-
如何提取、修改、强刷A卡bios a卡刷bios工具
-
Element Plus 的 Dialog 组件实现点击遮罩层不关闭对话框
-
日本组合“岚”将于2020年12月31日停止团体活动
-
SpringCloud OpenFeign 使用 okhttp 发送 HTTP 请求与 HTTP/2 探索
-
tinymce 号称富文本编辑器世界第一,大家同意么?
-
- 最近发表
- 标签列表
-
- dialog.js (57)
- importnew (44)
- windows93网页版 (44)
- yii2框架的优缺点 (45)
- tinyeditor (45)
- qt5.5 (60)
- windowsserver2016镜像下载 (52)
- okhttputils (51)
- android-gif-drawable (53)
- 时间轴插件 (56)
- docker systemd (65)
- slider.js (47)
- android webview缓存 (46)
- pagination.js (59)
- loadjs (62)
- openssl1.0.2 (48)
- velocity模板引擎 (48)
- pcre library (47)
- zabbix微信报警脚本 (63)
- jnetpcap (49)
- pdfrenderer (43)
- fastutil (48)
- uinavigationcontroller (53)
- bitbucket.org (44)
- python websocket-client (47)