this.$confirm与MessageBox.confirm的样式兼容处理

首先,我们会在开发过程中会涉及到对一些组件进行自定义样式处理,那么我们既不想重新去写一个,又能在原本的样式上面做改动。这就涉及到了对组件样式进行统一处理。接下来我将给大家分享一下我对提示弹框样式的处理。

涉及到this.$confirm样式改动,MessageBox.confirm样式却没有跟着变动,那么我就将两者合并处理。

首先,我们在main.js文件中对messageBox.confirm的样式进行一个处理。随后将样式给到this.$confirm。这样样式问题就解决了。

const newMessageBoxConfirm = MessageBox.confirm;
MessageBox.confirm = (...args) => {
  const defaultOptions = {
    center: true,
    showClose: false,
    type: 'warning',
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    customClass: 'custom-message-boxs',
  };
  const options = _.find(args, _.isPlainObject);
  if (options) {
    for (const key in defaultOptions) {
      if (key in options) continue;
      options[key] = defaultOptions[key]
    }
  } else {
    args.push(defaultOptions)
  }
  return newMessageBoxConfirm (...args);
};
Vue.prototype.$confirm = function (...args) {
  return MessageBox.confirm(...args);
};

解决最终两者样式统一问题

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值