$confirm的自定义使用

1 篇文章 0 订阅

$confirm的自定义使用

在项目开发过程中,经常会遇到需要修改ui库中默认样式的情况。就比如说使用element-ui的$confirm弹出框时,它的默认样式如下:
在这里插入图片描述
但我们需要的是
在这里插入图片描述这样一个布局样式,这时我们就需要对默认样式进行一个自定义修改,会利用消息框的自定义类名customClass,话不多说,直接进入正题~

交换取消和确定按钮

// js
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
  confirmButtonText: '确定',
  cancelButtonText: '取消',
  customClass:'demo1',
  type: 'warning'
}).then(() => {
    this.$message({
    type: 'success',
    message: '删除成功!'
  });
}).catch(() => {
  this.$message({
    type: 'info',
    message: '已取消删除'
  });          
});

// 样式
// 注意:样式不能放在 scoped 中
.delmo1 {
  .el-message-box__btns {
    .el-button:nth-child(1) {
      float:right;
    }
    .el-button:nth-child(2) {
      margin-right:10px;
      background-color:#2d8cf0;
      border-color:#2d8cf0;
    }
  }
}

修改后的结果如下:
在这里插入图片描述

自定义布局

const foo = this.$createElement
this.$confirm('', {

  message:h('div',null, [
    foo('i',{ class:'el-icon-question',style:'color:#f90;font-size:30px;' }),
    // 样式1
    foo('span',{ class: 'el-confirm-span'}, '提示'),
    // 样式2
    foo('p',{ style:'margin:10px 0 0 40px;color: #999999;' },'此操作将永久删除该文件, 是否继续?')
  ]),
  confirmButtonText: '确定',
  cancelButtonText: '取消',
  customClass:'demo2',
  closeOnClickModal:false,
  closeOnPressEscape:false,
})
  .then(() => {
    this.$message({
      type: 'success',
      message: '删除成功!'
    });
  })
  .catch(() => {
    this.$message({
      type: 'info',
      message: '已取消删除'
    });          
  });

// 样式1
.el-confirm-span {
  margin-left: 10px;
  font-size: 16px;
  line-height: 30px;
  font-weight: 600;
  vertical-align: top;
}

类名是方便自定义样式,当然这里的样式也是最好不要放到scope中,下面是修改后的结果:
在这里插入图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值