dva控制元素动态消失隐藏

posted @   marvelousone  阅读(2109)  评论(3编辑  收藏  举报

首先是component里面的jsx页面,这里用了AntDesigne的Alert

1
2
3
4
5
6
7
8
9
10
11
{!this.props.selfInfo.hidden?(
      <span className={styles.updateSuccess}>
      <Alert
        message={this.props.selfInfo.msg}
        type= {this.props.selfInfo.alertType} //"success" "erroe"
        closable
        onClose={onClose}
        showIcon
      />
    </span>):null
    }

  然后是component里state添加一个secon:3设置3秒消失

复制代码
  if(this.props.selfInfo.hidden!=true)
    {
     
      let timer = setInterval(() => {
        this.setState((preState) =>({
          seconds: preState.seconds - 1,
        }),() => {
          if(this.state.seconds == 0){
            clearInterval(timer);
          }
        });
      }, 1000)
    }
    if (this.state.seconds === 0) {
      this.props.selfInfo.hidden=true;
      if(this.props.selfInfo.msg=="获取用户登录信息失败"){
        this.props.dispatch(routerRedux.push({
          pathname: "/"
        }))
      }
      this.setState({seconds:3});
    }
复制代码

然后models里面state

hidden:true,
alertType:"None",
msg:"None",

再在models里面写个更改方法

复制代码
  updateStatus(state, action) {
      return { 
        ...state,
        hidden:action.hidden,
        alertType:action.alertType,
        msg:action.msg,
       
       };
    },
复制代码
yield put({ type: 'updateStatus' ,hidden:false,alertType:"error",msg:response.data.msg});
调用就好了。
编辑推荐:
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
阅读排行:
· 本地部署 DeepSeek:小白也能轻松搞定!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 从 Windows Forms 到微服务的经验教训
· 李飞飞的50美金比肩DeepSeek把CEO忽悠瘸了,倒霉的却是程序员
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
点击右上角即可分享
微信分享提示

喜欢请打赏

扫描二维码打赏

先送你一个公交红包啦~