element-ui this.$notify使用html作为内容 包括事件 禁止面板重叠 关闭面板

本文介绍如何在Vue中实现自定义的Notify通知面板,并通过示例代码详细讲解了其用法,包括如何避免面板重叠及如何关闭指定或所有通知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果

在这里插入图片描述

通知内容

  • 先把notify面板要显示的内容组织好 语法很容易看懂
	const h = this.$createElement
	const hrender = h('p', null, [
          h('div', [
            h('div',title), // 传变量
            h('div',content),
            h('div',author),
            h('div',time),
            ], null),
          h('button', {
            class: '样式',
            // 点击事件
            // on:{
              // click:this.doSth(parameters) // 不能传参,否则会自动执行
            // }
          }, "做事情"),
          ])

通知主体 根据官网写法

	this.$notify({
            title: '提示',
            dangerouslyUseHTMLString: true,
            message: hrender,
            type: 'warning',
            position: 'bottom-right',
            duration: 0,
            // showClose: false,
            onClick: () => {
              this.toApproval(approvalQuery)
            },
            onClose: () => {
              console.log(`Notify已关闭,说明异常或已查看`)
            }
          })

禁止面板重叠

  • 批量生成notify面板会重叠在一起
  • 定义
data() {
      return {
        notifyPromise: Promise.resolve(),
... ...
  • 使用箭头函数
this.notifyPromise = this.notifyPromise.then(this.$nextTick).then(()=>{ // 禁止重叠
	this.$notify({
	... ...
})

关闭

关闭某个
const instance = this.$notify({
... ...
instance.close()
关闭全部
this.$notify.closeAll()
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值