千家信息网

react封装全局弹框的方法是什么

发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,这篇文章主要讲解了"react封装全局弹框的方法是什么",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"react封装全局弹框的方法是什么"吧!弹框效果图
千家信息网最后更新 2025年02月02日react封装全局弹框的方法是什么

这篇文章主要讲解了"react封装全局弹框的方法是什么",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"react封装全局弹框的方法是什么"吧!

弹框效果图

文件布局

index.js

/* eslint-disable react/no-render-return-value */import React, { Component } from 'react'import { is, fromJS } from 'immutable'import ReactDOM from 'react-dom'import './alert.less'const close = require('../images/guanbi.png')const line = require('../images/line.png')const defaultState = {  alertStatus: false,  alertTip: null,  alertTitle: '详情',  closeAlert: () => {}}class Toptips extends Component {  state = {    ...defaultState  }  // css动画组件设置为目标组件  FirstChild = props => {    const childrenArray = React.Children.toArray(props.children)    return childrenArray[0] || null  }  // 关闭弹框  confirm = () => {    const that = this    console.log(that)    this.setState(      {        alertStatus: false      },      () => {        that.state.closeAlert()      }    )  }  open = data => {    const options = data || {}    options.alertStatus = true    this.setState({      ...defaultState,      ...options    })  }  close = () => {    const that = this    that.state.closeAlert()    this.setState({      ...defaultState    })  }  shouldComponentUpdate = (nextProps, nextState) => {    return (      !is(fromJS(this.props), fromJS(nextProps)) ||      !is(fromJS(this.state), fromJS(nextState))    )  }  render() {    const { alertStatus, alertTip, alertTitle } = this.state    console.log(alertTip, alertTitle)    return (        
{alertTitle}
line
{alertTip}
{ this.confirm() }} className="alert-close" src={close} alt="关闭" />
) }}const div = document.createElement('div')const props = {}document.body.appendChild(div)const Box = ReactDOM.render(React.createElement(Toptips, props), div)export default Box

less

.alert-con {  position: fixed;  top: 0;  left: 0;  width: 100%;  height: 100%;  background: rgba(255, 255, 255, 0.3);  z-index: 222;}.alert-context {  // background-color: #fff;  // border-radius: 16px;  position: relative;  // height: 500px;  height: 90%;  width: 750px;  margin: 40px auto 0;  background: url(../images/alertBJ.png) no-repeat center;  background-size: 100% 100%;  .alert-close{    width: 30px;    height: 30px;    position: absolute;    right: 30px;    top: 30px;  }  .alert-content-title{    width: 100%;    height: 80px;    line-height: 80px;    color: #fff;    text-align: center;    font-size: 36px;    font-weight: bolder;    // background: url(../images/line.png) no-repeat left bottom;  }  .alert-content-line{    width: 100%;    height: 20px;    margin-top: -44px;    margin-left: -6px;  }  .alert-detais-list{    width: 102%;    height: 100%;    overflow-y: auto;    padding: 20px 60px;    .alert-detais-list-C{      p{        &:nth-child(1){          font-size: 14px;          line-height: 20px;          color: #FFFFFF;          letter-spacing: 1.4px;        }        &:nth-child(2){          line-height: 24px;          font-size: 18px;          color: #FFFFFF;        }      }    }  }  .alert-content-detail{    // height: 100%;    height: calc(100% - 100px);    /* overflow-y: auto; */    overflow: hidden;    width: 98%;    margin-top: -26px;  }  .alert-details-pdf{    width: 102%;    height: 100%;    overflow-y: auto;    padding: 20px 60px;    .alert-details-button{      display: flex;      flex-direction: row;      justify-content: flex-end;      margin-bottom: 10px;      p{        color:#fff;        line-height: 35px;        font-size: 16px;        margin-right: 20px;      }      a{        line-height: 35px;        font-size: 16px;        margin-right: 20px;      }    }  }.cameraWrap{  width: 100%;  height: 102%;  box-sizing: border-box;  padding: 12px 4px 0 14px;}}

用法

alertTitle 弹框标题
alertTip 弹框内容,样式自己自定义
closeAlert 关闭时候返回信息,可要可不要,根据自己需求。

import Toptips from "./Toptips"Toptips.open({      alertTitle: '批示详情',      alertTip: that.htms(val),      closeAlert: function () {        console.log("关闭了...");      }    });  htms = val => {    return (

批示内容:

{val.fdTitle}

批示详述:

{val.fdTitle}

措施及结果:

{val.fdContent}

进度详情:

) }

感谢各位的阅读,以上就是"react封装全局弹框的方法是什么"的内容了,经过本文的学习后,相信大家对react封装全局弹框的方法是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

全局 方法 封装 内容 详情 学习 组件 可不 信息 动画 就是 布局 思路 情况 措施 效果 效果图 文件 文章 时候 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 软件开发顶层设计的概念 零极分布式网络技术推广 榆林软件开发价格走势 如何让服务器解码视频 水利局网络安全建设 普洱服务器显卡供应商 地质工作程度数据库涵盖 迅合科技微型网络服务器 学习护苗网络安全心得 基于构件软件开发方法的问题 数据库的学习在计算机中有啥意义 网络安全归纳几个过程 军职网络技术与应用作业答案 单位网络安全措施 武汉软件开发外包服务公司 中控管理服务器 笔记本关网络安全模式 浙江网络安全咨询报价 互联网在科技方面 手机软件开发是不是保合了 简单的网络安全报告 南京创新网络技术联系方式 网络技术发达英语作文 电脑mc联机无法连接服务器 智慧门禁软件开发机构 我的世界手游惊变100天服务器号 浙江通信网络安全防护测评流程 教育系统网络安全风险点 如何把网易材质包导入服务器 丰台网络安全大队
0