(记录笔记4)——4.3 Notification 通知提醒框

4.3 Notification 通知提醒框

全局展示通知提醒信息。

一.Notification组件

1.Notification组件

  • 引入Notification:import {notification} from “antd”;

    import { Button, notification } from 'antd';
    
    const openNotification = () => {
      notification.open({
        message: 'Notification Title',
        description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
      });
    };
    
    ReactDOM.render(
      <Button type="primary" onClick={openNotification}>Open the notification box</Button>,
      mountNode);
    
    • 效果如下:

二.实例一(通知提醒)

//src\pages\ui\notice.js
import React from "react";
import { Card, Button, notification } from "antd";
import "./ui.less";
export default class Notice extends React.Component {
  state = {};
  handleOpen = type => {};
  handleConfirm = type => {};
  openNotifications = type => {
    notification[type]({
      message: "发工资了",
      description: "上个月考勤22天,迟到12天,实发工资250,请笑纳"
    });
  };
  handleOk = () => {};
  render() {
    return (
      <div>
        <Card title="通知提醒框" className="card-wrap">
          <Button
            type="primary"
            onClick={() => this.openNotifications("success")}
          >
            Success
          </Button>
          <Button type="primary" onClick={() => this.openNotifications("info")}>
            Info
          </Button>
          <Button
            type="primary"
            onClick={() => this.openNotifications("warning")}
          >
            Warning
          </Button>
          <Button
            type="primary"
            onClick={() => this.openNotifications("error")}
          >
            Error
          </Button>
        </Card>
   
      </div>
    );
  }
}

三.实例二(通知提醒 + 方向控制)

  • placement 弹出位置,可选 topLeft topRight bottomLeft``bottomRight string topRight
  • notification.config(options)
//src\pages\ui\notice.js
import React from "react";
import { Card, Button, notification } from "antd";
import "./ui.less";
export default class Notice extends React.Component {
  openNotifications = (type, direction) => {
    if (direction) {
      //如果配置了direction,说明执行了有方向的通知框,将placement设置为当前方向
      notification.config({
        placement:direction
      });
    }
    notification[type]({
      message: "发工资了",
      description: "上个月考勤22天,迟到12天,实发工资250,请笑纳"
    });
  };
  handleOk = () => {};
  render() {
    return (
      <div>
        <Card title="通知提醒框" className="card-wrap">
          <Button
            type="primary"
            onClick={() => this.openNotifications("success")}
          >
            Success
          </Button>
          <Button type="primary" onClick={() => this.openNotifications("info")}>
            Info
          </Button>
          <Button
            type="primary"
            onClick={() => this.openNotifications("warning")}
          >
            Warning
          </Button>
          <Button
            type="primary"
            onClick={() => this.openNotifications("error")}
          >
            Error
          </Button>
        </Card>
        <Card title="通知提醒框-方向控制" className="card-wrap">
          <Button
            type="primary"
            onClick={() => this.openNotifications("success", "topLeft")}
          >
            Success-TopLeft
          </Button>
          <Button
            type="primary"
            onClick={() => this.openNotifications("info", "topRight")}
          >
            Info-TopRight
          </Button>
          <Button
            type="primary"
            onClick={() => this.openNotifications("warning", "bottomLeft")}
          >
            Warning-BottomLeft
          </Button>
          <Button
            type="primary"
            onClick={() => this.openNotifications("error", "bottomRight")}
          >
            Error-BottomRight
          </Button>
        </Card>
      </div>
    );
  }
}

核心Api

  • notification.success(config)
  • notification.error(config)
  • notification.info(config)
  • notification.warning(config)
  • notification.warn(config)

核心config

参数说明通知提醒标题,必选类型string默认值
message通知提醒标题,必选string|ReactNode-
description通知提醒内容,必选string|ReactNode-
placement弹出位置,可选 topLeft topRight bottomLeft``bottomRightstringtopRight

还提供了一个全局配置方法,在调用前提前配置,全局一次生效。

  • notification.config(options)
notification.config({
  placement: 'bottomRight',
  bottom: 50,
  duration: 3,
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小李科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值