第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 React 中加載微調(diào)器

在 React 中加載微調(diào)器

紫衣仙女 2022-08-04 10:04:20
類(lèi)  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>            )}我應(yīng)該在哪里將加載變量放在condentDidMount中,以便在數(shù)據(jù)加載時(shí)保持其為真,在數(shù)據(jù)加載時(shí)保持為假
查看完整描述

3 回答

?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

exports class Loading extends Component {

    state = {

        sample: [],

        loading: true

    };


    componentDidMount() {

        this.setState({sample: sample, loading: false});

    }


    render() {

        return (

            <div> 

                {this.state.loading ? 

                    <Spinner /> : <Data />

                }

            </div>

        )

    }

}

檢查此方法。


查看完整回答
反對(duì) 回復(fù) 2022-08-04
?
慕標(biāo)琳琳

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以將狀態(tài)設(shè)置為在發(fā)出請(qǐng)求之前,然后設(shè)置為返回響應(yīng)之后(對(duì)于成功和失敗的響應(yīng))。loadingtrueloadingfalse


async componentDidMount() {

  this.setState({

    loading: true

  }):


  this.sampleService

    .getAllSample()

    .then((sample) => {

      this.setState({

        sample, 

        loading: false,

      )}; 

     })

     .catch((err) => {

       console.log(err);

       this.setState({

         loading: false,

       )}; 

     });        

}


查看完整回答
反對(duì) 回復(fù) 2022-08-04
?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊

您可以將其設(shè)置為函數(shù),并在 AJAX 調(diào)用之前設(shè)置為 ,并將其設(shè)置為在接收數(shù)據(jù)后。您還可以將其設(shè)置為在錯(cuò)誤情況下async/awaitloadingtruefalsefalse


試試這樣的東西


async componentDidMount() {

    this.setState({loading: true});

    try

    {

       const res = await this.sampleService.getAllSample();

       this.setState({sample: res, loading: false);

    }

    catch(err)

    {  

       this.setState({loading:false});

       console.log(err);

    }         

 }


查看完整回答
反對(duì) 回復(fù) 2022-08-04
  • 3 回答
  • 0 關(guān)注
  • 123 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)