message-box中,有时候,官方文档给出的样式,无法满足自定义的需求,需要自己根据需求进行自定义解决,例如修改退出按钮的背景色及字体颜色。message-box的confirmButtonClass支持自定义按钮样式。注意<style>中不能有scoped否则样式不能生效。
confirmButtonClass 取消按钮的样式,用法与confirmButtonClass一致。
<template>
<el-button text @click="open">Click to open the Message Box</el-button>
</template>
<script lang="ts" setup>
import { ElMessage, ElMessageBox } from 'element-plus'
const open = () => {
ElMessageBox.confirm(
'proxy will permanently delete the file. Continue?',
'Warning',
{
confirmButtonText: '退出',
cancelButtonText: '取消',
type: 'warning',
confirmButtonClass:'ExitConfirmButton'
}
)
.then(() => {
ElMessage({
type: 'success',
message: 'Delete completed',
})
})
.catch(() => {
ElMessage({
type: 'info',
message: 'Delete canceled',
})
})
}
</script>
//style中不能加入scoped,否则样式不生效
// !important 优先使用
<style>
.ExitConfirmButton{
background: #751d1d !important;
color: #fff !important;
}
</style>