(记录笔记4)——4.2 Spin组件的使用

4.2 Spin组件的使用

用于页面和区块的加载中状态。

何时使用#

Spin(英文意思:旋转),用于页面局部需要进行加载的页面使用

合适的加载动效会有效缓解用户的焦虑。

一.Spin组件

1.Spin组件

  • 引入Card:import {Spin} from ‘antd’;

  • import React from "react";
    import "./ui.less";
    import { Card, Button, Spin, Icon, Alert } from "antd";
    
    export default class Loadings extends React.Component {
      render() {
        return (
          <div>
            <Card title="Spin用法" className="card-wrap">
              <Spin />
            </Card>
          </div>
        );
      }
    }
    
  • 效果如下:

  • indicator: indicator={icon}加载指定的图标

    • const icon = <Icon type="loading"/>;
    • <Spin indicator={icon}/>
  • size:small/default/large 设置大小

  • 注意:style={{marginLeft:10}},marginLeft:xx ,xx是数字可以省略px

  • 如果是style={{margin:'0 10px'}},xx 是字符串的情况,则不能省略px

  • style={{fontSize:24}} 调整显示图标的大小

  • tip:当作为包裹元素时,可以自定义描述文案

  • tip:"加载中"

    //src\pages\ui\loadings.js
    import React from "react";
    import "./ui.less";
    import { Card, Button, Spin, Icon, Alert } from "antd";
    
    export default class Loadings extends React.Component {
      render() {
        const icon = <Icon type="loading" style={{ fontSize: 24 }}/>;
        return (
          <div>
            <Card title="Spin用法" className="card-wrap" >
              <Spin size="small" />
              <Spin size="default" style={{margin:'0 10px'}} />
              <Spin size="large" />
              <Spin indicator={icon} style={{marginLeft:10}}/>
            </Card>
          </div>
        );
      }
    }
    
    

二.Alert组件

警告提示,展现需要关注的信息。

import { Alert } from 'antd';

ReactDOM.render(
  <Alert message="Success Text" type="success" />,
  mountNode);

1.Alert组件

  • 引入Card:import {Alert} from ‘antd’;

  • type指定警告提示的样式,有四种选择 successinfowarningerror
    message警告提示内容(设置标题信息)
    description警告提示的辅助性文字介绍(设置具体描述的内容)
    type指定警告提示的样式,有四种选择 successinfowarningerror

    基本实例

    //src\pages\ui\loadings.js
    import React from "react";
    import "./ui.less";
    import { Card, Button, Spin, Icon, Alert } from "antd";
    
    export default class Loadings extends React.Component {
      render() {
        const icon = <Icon type="loading" style={{ fontSize: 24 }}/>;
        return (
          <div>
            <Card title="Spin用法" className="card-wrap" >
              <Spin size="small" />
              <Spin size="default" style={{ margin: "0 10px" }} />
              <Spin size="large" />
              <Spin indicator={icon} style={{ marginLeft: 10 }} />
            </Card>
            <Card title="内容遮罩" className="card-wrap">
              <Alert 
              message="React" 
              description="欢迎来到React高级实战课程!"
              type="info"
              />
            </Card>
          </div>
        );
      }
    }
    
    
  • 完整效果

  • //src\pages\ui\loadings.js
    import React from "react";
    import "./ui.less";
    import { Card, Button, Spin, Icon, Alert } from "antd";
    
    export default class Loadings extends React.Component {
      render() {
        const icon = <Icon type="loading" style={{ fontSize: 24 }}/>;
        return (
          <div>
            <Card title="Spin用法" className="card-wrap" >
              <Spin size="small" />
              <Spin size="default" style={{ margin: "0 10px" }} />
              <Spin size="large" />
              <Spin indicator={icon} style={{ marginLeft: 10 }} />
            </Card>
            <Card title="内容遮罩" className="card-wrap">
              <Alert 
              message="React" 
              description="欢迎来到React高级实战课程!"
              type="info"
              />
              <Alert 
              message="React" 
              description="欢迎来到React高级实战课程!"
              type="warning"
              />
            </Card>
          </div>
        );
      }
    }
    

三.Alert组件蒙版效果

Spin组件内部使用自闭和(使颜色变浅)

  • tip当作为包裹元素时,可以自定义描述文案
    + tip:“加载中”
    + style={{ marginTop: 10}} :调整页面间距
  • 完整实例代码

  • //src\pages\ui\loadings.js
    import React from "react";
    import "./ui.less";
    import { Card, Button, Spin, Icon, Alert } from "antd";
    
    export default class Loadings extends React.Component {
      render() {
        const icon = <Icon type="loading" style={{ fontSize: 24 }} />;
        const iconLoading = <Icon type="loading" style={{ fontSize: 24 }} />;
        return (
          <div>
            <Card title="Spin用法" className="card-wrap">
              <Spin size="small" />
              <Spin size="default" style={{ margin: "0 10px" }} />
              <Spin size="large" />
              <Spin indicator={icon} style={{ marginLeft: 10 }} />
            </Card>
            <Card title="内容遮罩" className="card-wrap">
              <Alert
                message="React"
                description="欢迎来到React高级实战课程!"
                type="info"
              />
    
              <Spin>
                <Alert
                  message="React"
                  description="欢迎来到React高级实战课程!"
                  type="warning"
                  style={{ marginTop: 10 }}
                />
              </Spin>
              <Spin tip="加载中...">
                <Alert
                  message="React"
                  description="欢迎来到React高级实战课程!"
                  type="warning"
                  style={{ marginTop: 10 }}
                />
              </Spin>
              <Spin indicator={iconLoading} tip="加载中...">
                <Alert
                  message="React"
                  description="欢迎来到React高级实战课程!"
                  type="warning"
                  style={{ marginTop: 10}}
                />
              </Spin>
            </Card>
          </div>
        );
      }
    }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小李科技

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

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

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

打赏作者

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

抵扣说明:

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

余额充值