每日一写(更改element-UI消息弹框$notify的样式修改问题)

element-UI消息弹框$notify的样式修改问题

需求:
发消息页面发送成功或者后进行消息弹出提示

在这里插入图片描述

解决:使用element-ui的Notification 通知组件

组件官网地址

 this.post(
          '~~~~',
          data,
          (data) => {
            if (data.success == 'true') {
              // this.$message.success('您的消息已发送成功')
             this.$notify({
                title: '成功',
                message: '发送成功',
                dangerouslyUseHTMLString: true,
                type: 'success',
              });
              // 重置页面数据
              this.addArr = []
              this.title = ''
              this.addressee = []
              this.content = ''
              this.time1 = ''
              this.time2 = ''
              // delCookie(this.errorSendMessage.id) // 发送成功的消息需要进行删除cookie
            }

但是显示的是这样的
在这里插入图片描述

修改样式

步骤一:customClass:'notify-success' 添加customClass属性覆盖原有样式
 this.$notify({
                title: '成功',
                message: '发送成功',
                dangerouslyUseHTMLString: true,
                type: 'success',
                customClass:'notify-success'
              });

步骤二:在全局进行书写css样式(全局是重点)
为什么是全局?
因为添加的消息弹层div不在当前组件下面,也不在APP.vue的div下面,它的div标签和app.vue平级
实现:在当前的发消息的vue组件页面加入style,但是不要加scoped属性,用!important进行加权

<style>
.notify-success{
    top: 1.7rem !important;
    right: 0.32rem !important;
    width: 2rem !important;
    height: 0.96rem !important;
    background: rgba(131, 213, 134, 0.1) !important;
    border-radius: 0.04rem 0px 0px 0.04rem !important;
}
.notify-error{
    top: 2.7rem !important;
    right: 0.32rem !important;
    width: 2rem !important;
    height: 0.96rem !important;
    background:  rgba(255, 31, 36, 0.05) !important;
    border-radius: 0.04rem 0px 0px 0.04rem !important;
}
</style>
  • 7
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值