在 componentWillReceiveProps 函数中调用 setTimeout 函数时出现 500 错误。
当我没有在 chrome 中调试时出现以下错误图像
我在 chrome 中调试时遇到以下错误
可以引用下面的代码
componentWillReceiveProps(nextprops){
this.setState({isLoading:true})
var data =[];
if(nextprops.tasks.length == 0){
//this.setState({isLoading:false,isEmpty:true})
}else{
this.setState({ dataSource:ds.cloneWithRows(nextprops.tasks),isLoading: false, isError: false, isEmpty: false });
}
setTimeout(() => {
if(nextprops.tasks.length == 0){
this.setState({isLoading:false,isEmpty:true})
}else{
this.setState({ dataSource:ds.cloneWithRows(nextprops.tasks), isLoading: false, isError: false, isEmpty: false });
}
},5000);
}
最佳答案
Visual Studio 自动添加
import {setTimeout} from "timers";
检查您的导入并将其删除。 setTimeout 函数不需要导入。
关于javascript - 在 componentWillReceiveProps 函数中调用 setTimeout 时无法解析模块计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49048427/