Vue ElementUI 修改消息提示框样式—messageBox 的大小

在窄屏模式下(移动端或pda),提示框的宽度太宽,会出现显示不完全的问题。 应当如何修改 ElementUI 的样式呢?

在这里插入图片描述

  open() {
      this.$confirm(
        window.vm.$i18n.t("tips.conLogOut"),
        window.vm.$i18n.t("tips.tip"),
        {
          confirmButtonText: window.vm.$i18n.t("backTips.confirm"),
          cancelButtonText: window.vm.$i18n.t("backTips.cancel"),
          type: "warning",
        }
      ).then(() => {
        this.logout();
      });
    },
 <style scoped>
  .el-message-box {
    width: 235px;
}
</style>

在这里插入图片描述
此时在scoped的style中写是无效的,因为ElementUI组件不可以给样式添加scoped,因此必须去掉scoped;但是去掉scoped后不满足单组件的CSS。

解决方案

1、附加在没有scoped的style中

<style scoped>
  ...
</style>
<style>
  ...
  .el-message-box {
    width: 235px;
  }
</style>

在这里插入图片描述
2、给消息提示框加类名(荐)
更加推荐这个messageBox添加一个类名,比较好用并且不会影响到其他页面的弹框样式。
在这里插入图片描述

this.$confirm('确认注销吗?', '提示', {
  customClass: 'elmessageWidth'
}).then(() => {
  this.$message({
    message: '已成功注销',
    type: 'success'
  })
}).catch(() => {  })
<style scoped>
  ...
</style>
<style>
 .elmessageWidth {
    width: 350px;
  }
</style>

或者直接important

@media (max-width: 730px) {
  .elmessageWidth{
    width: 350px !important;
  }
 }

在这里插入图片描述

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值