ant-vue通知提醒框( Notification )实现自定义样式

本文档展示了如何在Ant Design的通知提醒组件中使用`vueNode`或`function(h)`实现自定义样式和功能。通过绑定事件和指令,实现了点击图标时颜色变化的效果,同时也探讨了在实现过程中遇到的问题及其解决方案,如点击icon颜色渲染和位置调整等。

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

需求:运用ant中通知提醒实现自定义的样式效果;

效果如下:点我之后点击上传按钮去看效果

在这里插入图片描述

组件自定义内容支持vueNode |function(h),我自己是用function(h)来实现的,想用vueNode的 可以去vue 官网去查看 相应的编码规范,function(h)的其中核心有点像广度遍历似的,大家可以先将要实现的代码先写出来之后再用function(h) 来实现 更高效:

我不知道怎么绑定指令,问我的狗子 他也不知道,真希望有高人指点一番!!!

 h(
              '页面标签',
              {
                props: {
                 '此处写相应的标签属性'
                },
                attrs: {
                 '此处可以写相应的样式,绑定class'
                }on: {
                 '此处绑定事件,click'
                }
              },
              ['此处是子内容,实现也是跟上面一样']
  )            

主要实现代码如下:

遇到一个小问题 就是点击icon转换的过程中,颜色没有渲染上,而且位置也发生变化,狗子说,我也没看到什么好的方案,最后用 e.currentTarget.style.color = ‘#3579ff’ 这样实现的

在这里插入图片描述

在这里插入图片描述

 //上传进度通知栏
    openNotification() {
      const key = `open${Date.now()}`
      this.$notification.open({
        message: this.formMirrorData.fileName,
        description: h => {
          return h('div', null, [
            h(
              'a-row',
              {
                props: {
                  type: 'flex'
                },
                attrs: {
                  style: 'margin: 25px 0 10px;'
                }
              },
              [
                h(
                  'a-col',
                  {
                    props: {
                      flex: 'auto'
                    }
                  },
                  [
                    h('a-progress', {
                      props: {
                        percent: this.percent,
                        showInfo: false
                      },
                      attrs: {
                        style: 'width:82%'
                      }
                    }),
                    h(
                      'span',
                      {
                        attrs: {
                          style:
                            'color: rgba(0,0,0,.45);font-size: 1em;margin-left: 12px;'
                        }
                      },
                      `${this.percent}%`
                    )
                  ]
                ),
                h(
                  'a-col',
                  {
                    props: {
                      flex: '38px'
                    },
                    attrs: {
                      style: 'margin-top:2px;'
                    }
                  },
                  [
                    h('a-space', null, [
                      h('a-icon', {
                        props: {
                          type: this.startOrStopFlag ? 'pause' : 'caret-right'
                        },
                        attrs: {
                          class: ['infoText']
                        },
                        on: {
                          click: e => {
                            this.startOrStopFlag = !this.startOrStopFlag
                            //e.currentTarget 返回其事件监听器触发该事件的元素e.target(事件的目标节点)
                            e.currentTarget.style.color = '#3579ff'
                          }
                        }
                      }),
                      h('a-icon', {
                        props: {
                          type: 'close'
                        },
                        attrs: {
                          class: ['infoText'],
                          style: 'font-size: 12px;'
                        },
                        on: {
                          click: e => {
                            this.$notification.destroy()
                          }
                        }
                      })
                    ])
                  ]
                )
              ]
            ),
            h(
              'div',
              {
                attrs: {
                  style: 'margin-bottom:20px;font-size:16px'
                }
              },
              bytesToSize(this.fileList[0].size)
            ),
            h(
              'div',
              {
                attrs: {
                  class: ['errorText']
                }
              },
              'Upload is not completed, please do not switch pages!'
            )
          ])
        },
        key,
        duration: null,
        placement: 'bottomRight',
        onClose: () => {
          console.log(
            'Notification was closed. Either the close button was clicked or duration time elapsed.'
          )
        }
      })
    },
Ant Design Vue (ant-design-vue) 中,要自定义`Tabs`组件(选项卡)的按钮样式,你可以通过覆盖内置的CSS样式或者使用Vue的 scoped CSS(局部样式)。以下是两种常见的做法: 1. **覆盖内置样式**: - 首先,找到原生tabs按钮的类名,通常它们是`.ant-tabs-tab`、`.ant-tabs-tab-active`等。你可以查看官方文档或直接在开发者工具的Elements面板里查找。 - 使用`:deep()`或`::v-deep`来穿透到内部元素,然后在你的Vue组件的样式文件(如`styles.css`或`.vue`文件内)添加如下CSS: ```css .ant-tabs-tab { /* 在这里添加你的自定义样式 */ color: your-color; background-color: your-background-color; border-radius: your-border-radius; } .ant-tabs-tab-active { /* 对激活状态的样式进行定制 */ color: your-active-color; background-color: your-active-background-color; } ``` 2. **使用Scoped CSS(局部样式)**: 如果你想要只针对某个特定的tabs组件应用样式,可以在对应的`<Tabs>`标签内部使用`style`属性,并使用`:is`伪类配合变量(如果使用的是Vue 3+): ```html <template> <Tabs :tabs="yourTabsData" @on-change="handleChange"> <TabPane v-for="(item, index) in yourTabsData" :key="index" :label="item.label" :name="item.name"> <!-- 内容 --> <div slot="content">{{ item.content }}</div> </TabPane> </Tabs> </template> <script setup> // ... </script> <style scoped> /* 这里的选择器仅限于当前组件的Tab按钮 */ .ant-tabs-tab.is-selected { /* 自定义样式 */ } </style> ``` 记得在实际使用时替换`your-color`、`your-background-color`等为你的目标颜色值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值