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 }) }