1.在子组件内对数组进行删减后打印数据有变化但是页面没重新渲染

原始写法

 deleteBtnClick(index){
        let tempList = this.state.attachList;
        tempList.splice(index,1)
        this.setState({
            attachList: tempList
        });
    }

解决办法

 deleteBtnClick(index){
        let tempList = this.state.attachList;
        tempList.splice(index,1)
        this.setState((prevState) =>{
            delete prevState.attachList;
            return prevState;
        })
        this.setState({
            attachList:tempList
        })

    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2021-07-30
相关资源
相似解决方案