在窄屏模式下(移动端),提示框的宽度太宽,会出现显示不完全的问题。
应当如何修改 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>

![在这里插入图片描述](https://img-blog.csdnimg.cn/722760c42706472595ef8eb26ba7fbaf.png

此时在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: 'message-logout'
}).then(() => {
  this.$message({
    message: '已成功注销',
    type: 'success'
  })
}).catch(() => {  })
...
<style scoped>
  ...
</style>
<style>
  ...
  .message-logout {
    width: 350px;
  }
</style>

或者直接important

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

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐