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

相关文章

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

css渐变色背景|<gradient示例详解

《css渐变色背景|<gradient示例详解》CSS渐变是一种从一种颜色平滑过渡到另一种颜色的效果,可以作为元素的背景,它包括线性渐变、径向渐变和锥形渐变,本文介绍css渐变色背景|<gradien... 使用渐变色作为背景可以直接将渐China编程变色用作元素的背景,可以看做是一种特殊的背景图片。(是作为背

C++实现封装的顺序表的操作与实践

《C++实现封装的顺序表的操作与实践》在程序设计中,顺序表是一种常见的线性数据结构,通常用于存储具有固定顺序的元素,与链表不同,顺序表中的元素是连续存储的,因此访问速度较快,但插入和删除操作的效率可能... 目录一、顺序表的基本概念二、顺序表类的设计1. 顺序表类的成员变量2. 构造函数和析构函数三、顺序表

CSS自定义浏览器滚动条样式完整代码

《CSS自定义浏览器滚动条样式完整代码》:本文主要介绍了如何使用CSS自定义浏览器滚动条的样式,包括隐藏滚动条的角落、设置滚动条的基本样式、轨道样式和滑块样式,并提供了完整的CSS代码示例,通过这些技巧,你可以为你的网站添加个性化的滚动条样式,从而提升用户体验,详细内容请阅读本文,希望能对你有所帮助...

css实现图片旋转功能

《css实现图片旋转功能》:本文主要介绍了四种CSS变换效果:图片旋转90度、水平翻转、垂直翻转,并附带了相应的代码示例,详细内容请阅读本文,希望能对你有所帮助... 一 css实现图片旋转90度.icon{ -moz-transform:rotate(-90deg); -webkit-transfo

Go语言利用泛型封装常见的Map操作

《Go语言利用泛型封装常见的Map操作》Go语言在1.18版本中引入了泛型,这是Go语言发展的一个重要里程碑,它极大地增强了语言的表达能力和灵活性,本文将通过泛型实现封装常见的Map操作,感... 目录什么是泛型泛型解决了什么问题Go泛型基于泛型的常见Map操作代码合集总结什么是泛型泛型是一种编程范式,允

vue基于ElementUI动态设置表格高度的3种方法

《vue基于ElementUI动态设置表格高度的3种方法》ElementUI+vue动态设置表格高度的几种方法,抛砖引玉,还有其它方法动态设置表格高度,大家可以开动脑筋... 方法一、css + js的形式这个方法需要在表格外层设置一个div,原理是将表格的高度设置成外层div的高度,所以外层的div需要