dva控制元素動態消失隱藏


首先是component里面的jsx頁面,這里用了AntDesigne的Alert

  {!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});
調用就好了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM