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">
					<span
						class="mr10 font20"
						:class="iconClass"
						:style="iconStyle"
						v-if="popoverIcon"
					></span
					>{{ textMessage }}
				</p>
				<!-- 自定义提示内容 -->
				<slot></slot>
			</div>
			<div class="operate-btns mt20">
				<el-button
					size="medium"
					plain
					class="w45pct"
					@click="visible = false"
					>{{ cancelTxt }}</el-button
				>
				<el-button
					size="medium"
					type="primary"
					class="w45pct mlpct10-imp"
					@click="fireHandler"
					>{{ confirmTxt }}</el-button
				>
			</div>
			<el-button
				v-if="!advancedBtn"
				:type="adsorptionBtnType"
				:plain="isPlain"
				:icon="adsorptionBtnIcon"
				:style="falseBtnContentStyle"
				:disabled="btnDisabled"
				size="medium"
				slot="reference"
				@click="referChange"
			>
				{{ adsorptionTxt }}
			</el-button>
			<el-button
				v-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,
		},
		//是否需要icon
		popoverIcon: {
			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,
		},
		//被吸附的按钮的icon
		adsorptionBtnIcon: {
			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-popover
	v-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-popover
	v-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-group
			  v-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() {}

相关推荐

  1. elemeentui el-table封装

    2024-06-07 09:36:04       31 阅读
  2. vue form表单封装--使用elementUI

    2024-06-07 09:36:04       43 阅读
  3. vue2组件封装+elementUI

    2024-06-07 09:36:04       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-07 09:36:04       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-07 09:36:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-07 09:36:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-07 09:36:04       20 阅读

热门阅读

  1. 浅谈人机交互

    2024-06-07 09:36:04       5 阅读
  2. 人机交互中的阴差阳错

    2024-06-07 09:36:04       5 阅读
  3. 解决nginx无法获取带下划线的header值

    2024-06-07 09:36:04       8 阅读
  4. 单双目视频转图片

    2024-06-07 09:36:04       6 阅读
  5. 常见排序算法,快排,希尔,归并,堆排

    2024-06-07 09:36:04       7 阅读
  6. Elasticsearch简介

    2024-06-07 09:36:04       5 阅读
  7. scss sass是什么?vue环境安装sass报错

    2024-06-07 09:36:04       8 阅读
  8. GUI guider 常用函数解析

    2024-06-07 09:36:04       7 阅读
  9. 洛谷 P3870 [TJOI2009] 开关 题解 线段树

    2024-06-07 09:36:04       9 阅读
  10. 【C++刷题】优选算法——前缀和

    2024-06-07 09:36:04       7 阅读