类
class Loading extends Component<{},{}> {
state = {
sample: [],
loading: false
};
sampleService = new SampleService();
componentDidMount() {
this.sampleService
.getAllSample()
.then((sample) => {
this.setState((state) => {
return Object.assign(state, { sample: sample });
});
})
.catch((err) => {
console.log(err);
});
}
}
Component.tsx:
render(){
const {loading} = this.state
}
return(
{loading ? <Spinner/>: <data>
)}
我应该在哪里将加载变量放在condentDidMount中,以便在数据加载时保持其为真,在数据加载时保持为假
紫衣仙女
一只斗牛犬
慕标琳琳
守候你守候我
随时随地看视频慕课网APP
相关分类