Vue 封装elementUI的el-popover

2024-06-06 18:28

本文主要是介绍Vue 封装elementUI的el-popover,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.封装公共组件
<template><div class="confirm-popover disInlineBlock ml10"><el-popover placement="bottom" v-model="visible" :trigger="triggerType"><div class="confirm-popover-popover"><!-- 简单提示内容 --><p class="confimStyle" v-if="!advanced"><spanclass="mr10 font20":class="iconClass":style="iconStyle"v-if="popoverIcon"></span>{{ textMessage }}</p><!-- 自定义提示内容 --><slot></slot></div><div class="operate-btns mt20"><el-buttonsize="medium"plainclass="w45pct"@click="visible = false">{{ cancelTxt }}</el-button><el-buttonsize="medium"type="primary"class="w45pct mlpct10-imp"@click="fireHandler">{{ confirmTxt }}</el-button></div><el-buttonv-if="!advancedBtn":type="adsorptionBtnType":plain="isPlain":icon="adsorptionBtnIcon":style="falseBtnContentStyle":disabled="btnDisabled"size="medium"slot="reference"@click="referChange">{{ adsorptionTxt }}</el-button><el-buttonv-if="advancedBtn":type="adsorptionBtnType":plain="isPlain":style="btnContentStyle":icon="adsorptionBtnIcon":disabled="btnDisabled"size="medium"slot="reference"><slot name="btnContent"></slot></el-button></el-popover></div>
</template><script>
export default {name: "ConfirmPopover",props: {// 按钮大小size: {type: String,default: "small",},//被吸附的按钮是否禁用btnDisabled: {type: Boolean,default: false,},//是否朴素按钮isPlain: {type: Boolean,default: true,},//是否开启自定义提示内容advanced: {type: Boolean,default: false,},//是否开启自定义按钮内的内容(如果想自定义btn内容,advancedBtn必须为true)advancedBtn: {type: Boolean,default: false,},//是否需要iconpopoverIcon: {type: Boolean,default: true,},//popover中的icon 图标iconClass: {type: String,default: "el-icon-warning",},//popover中的icon 行内样式iconStyle: {type: Object,default: function () {return { color: "#f56c6c" };},},//btnContent中的icon 行内样式btnContentStyle: {type: Object,default: function () {return { color: "#f56c6c" };},},//falseBtnContentStyle中的icon 行内样式falseBtnContentStyle: {type: Object,default: function () {return { color: "#f56c6c" };},},//popover触发方式triggerType: {type: String,default: "click",required: false,},//提示文案textMessage: {type: String,default: "Hello world!!!",required: false,},//被吸附的按钮文案adsorptionTxt: {type: String,default: "按钮",required: false,},//被吸附的按钮的类型adsorptionBtnType: {type: String,default: "primary",required: false,},//被吸附的按钮的iconadsorptionBtnIcon: {type: String,default: "",required: false,},//取消按钮文案cancelTxt: {type: String,default: "取消",required: false,},//确认按钮文案confirmTxt: {type: String,default: "确定",required: false,},},components: {},computed: {},watch: {},data() {return {visible: false, //popover显示与隐藏};},mounted() {},methods: {fireHandler() {this.visible = false;this.$emit("emitCallback");},referChange() {this.visible = false;this.$emit("referBtn");},},
};
</script><style lang="scss" scoped>
::v-deep .el-icon-warning:before {content: "\e7a3" !important;
}
::v-deep .el-button {min-width: 60px;
}
.confirm-popover-popover {.confimStyle {color: #606266;font-size: 14px;}
}
</style>
2.使用场景

   2-1 单纯的弹出按钮框 类似于这种

   

1.引入
import confirmPopover from "@/components/ConfirmPopover";
components:{confirmPopover}
2.使用
<confirm-popoverv-if="libraryFlag.isCanDelete"class="deleteBtnActive ml10":textMessage="delMessage"adsorptionBtnType="danger"adsorptionBtnIcon="el-icon-delete"adsorptionTxt="删除":falseBtnContentStyle="falseBtnContentStyleObj"triggerType="manual"@referBtn="deleApply"ref="del"@emitCallback="delSure">
</confirm-popover>
3.data
delMessage: "请选择确认删除的数据?",
falseBtnContentStyleObj: {color: "#f9a7a7",borderWidth: "1px",borderColor: "#fde2e2",borderStyle: "solid",fontSize: "18px",lineHeight: "13px",fontWeight: 600,background: "none",
},
4.methods
deleApply() {this.visible = true;this.$refs.del.visible = true;
},
delSure() {}

2-2 结合el-radio的弹出框

1.引入
import confirmPopover from "@/components/ConfirmPopover";
components:{confirmPopover}
2.使用
<confirm-popoverv-if="libraryFlag.isCanDelete"class="deleteBtnActive ml10":textMessage="delMessage"adsorptionBtnType="danger"adsorptionBtnIcon="el-icon-delete"adsorptionTxt="删除":falseBtnContentStyle="falseBtnContentStyleObj"triggerType="manual"@referBtn="deleApply"ref="del"@emitCallback="delSure"><template slot="default"><div class="custom-message"><el-radio-groupv-model="selectedOption"style="display: flex; flex-direction: column"class="ml20 mt10"><el-radio label="1">删除已选{{ selectedCount }}条</el-radio><el-radio label="2" class="mt10">删除全部{{ totalCount }}条</el-radio></el-radio-group></div></template>
</confirm-popover>
3.data
delMessage: "请选择确认删除的数据?",
falseBtnContentStyleObj: {color: "#f9a7a7",borderWidth: "1px",borderColor: "#fde2e2",borderStyle: "solid",fontSize: "18px",lineHeight: "13px",fontWeight: 600,background: "none",
},
selectedOption: null,
selectedCount: 0,
totalCount: 0,
4.methods
deleApply() {this.visible = true;this.$refs.del.visible = true;
},
delSure() {}

这篇关于Vue 封装elementUI的el-popover的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1036880

相关文章

使用vscode搭建pywebview集成vue项目实践

《使用vscode搭建pywebview集成vue项目实践》:本文主要介绍使用vscode搭建pywebview集成vue项目实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录环境准备项目源码下载项目说明调试与生成可执行文件核心代码说明总结本节我们使用pythonpywebv

使用Python和Tkinter实现html标签去除工具

《使用Python和Tkinter实现html标签去除工具》本文介绍用Python和Tkinter开发的HTML标签去除工具,支持去除HTML标签、转义实体并输出纯文本,提供图形界面操作及复制功能,需... 目录html 标签去除工具功能介绍创作过程1. 技术选型2. 核心实现逻辑3. 用户体验增强如何运行

CSS 样式表的四种应用方式及css注释的应用小结

《CSS样式表的四种应用方式及css注释的应用小结》:本文主要介绍了CSS样式表的四种应用方式及css注释的应用小结,本文通过实例代码给大家介绍的非常详细,详细内容请阅读本文,希望能对你有所帮助... 一、外部 css(推荐方式)定义:将 CSS 代码保存为独立的 .css 文件,通过 <link> 标签

使用Vue-ECharts实现数据可视化图表功能

《使用Vue-ECharts实现数据可视化图表功能》在前端开发中,经常会遇到需要展示数据可视化的需求,比如柱状图、折线图、饼图等,这类需求不仅要求我们准确地将数据呈现出来,还需要兼顾美观与交互体验,所... 目录前言为什么选择 vue-ECharts?1. 基于 ECharts,功能强大2. 更符合 Vue

Vue中插槽slot的使用示例详解

《Vue中插槽slot的使用示例详解》:本文主要介绍Vue中插槽slot的使用示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、插槽是什么二、插槽分类2.1 匿名插槽2.2 具名插槽2.3 作用域插槽三、插槽的基本使用3.1 匿名插槽

springboot+vue项目怎么解决跨域问题详解

《springboot+vue项目怎么解决跨域问题详解》:本文主要介绍springboot+vue项目怎么解决跨域问题的相关资料,包括前端代理、后端全局配置CORS、注解配置和Nginx反向代理,... 目录1. 前端代理(开发环境推荐)2. 后端全局配置 CORS(生产环境推荐)3. 后端注解配置(按接口

Vue 2 项目中配置 Tailwind CSS 和 Font Awesome 的最佳实践举例

《Vue2项目中配置TailwindCSS和FontAwesome的最佳实践举例》:本文主要介绍Vue2项目中配置TailwindCSS和FontAwesome的最... 目录vue 2 项目中配置 Tailwind css 和 Font Awesome 的最佳实践一、Tailwind CSS 配置1. 安

CSS3 布局样式及其应用举例

《CSS3布局样式及其应用举例》CSS3的布局特性为前端开发者提供了无限可能,无论是Flexbox的一维布局还是Grid的二维布局,它们都能够帮助开发者以更清晰、简洁的方式实现复杂的网页布局,本文给... 目录深入探讨 css3 布局样式及其应用引言一、CSS布局的历史与发展1.1 早期布局的局限性1.2

使用animation.css库快速实现CSS3旋转动画效果

《使用animation.css库快速实现CSS3旋转动画效果》随着Web技术的不断发展,动画效果已经成为了网页设计中不可或缺的一部分,本文将深入探讨animation.css的工作原理,如何使用以及... 目录1. css3动画技术简介2. animation.css库介绍2.1 animation.cs

CSS引入方式和选择符的讲解和运用小结

《CSS引入方式和选择符的讲解和运用小结》CSS即层叠样式表,是一种用于描述网页文档(如HTML或XML)外观和格式的样式表语言,它主要用于将网页内容的呈现(外观)和结构(内容)分离,从而实现... 目录一、前言二、css 是什么三、CSS 引入方式1、行内样式2、内部样式表3、链入外部样式表四、CSS 选