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

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

如何在我的 Reactjs 計(jì)算器應(yīng)用程序上顯示計(jì)算器輸出

如何在我的 Reactjs 計(jì)算器應(yīng)用程序上顯示計(jì)算器輸出

墨色風(fēng)雨 2022-08-18 10:45:55
我正在使用一個(gè) reactjs 計(jì)算器應(yīng)用程序。它應(yīng)該像一個(gè)簡(jiǎn)單的手持計(jì)算器一樣工作。到目前為止,我已經(jīng)設(shè)法捕獲并顯示第一和第二操作數(shù)的用戶輸入以及要執(zhí)行的操作(+,-,/,*)使用狀態(tài)和setState。當(dāng)我按下“equals”按鈕時(shí),麻煩就來了,它應(yīng)該調(diào)用我稱之為EqualsSign()的函數(shù),以便獲得答案并將其顯示在屏幕上。無(wú)論我輸入什么數(shù)字,我都得到0作為答案。代碼如下:EqualsSign(){    this.A=parseFloat(this.state.operand)    console.log("A is ",this.A)// debuging line    this.B=parseFloat(this.state.operand2)    console.log("B is ", this.B)    switch(this.state.operation){        case "+":            console.log(this.state.operation)            this.setState({answer: (this.A+this.B).toString()}, console.log(this.state.answer))            this.setState({operand: this.state.answer, operand2: '', operation: ''})            break        case "-":            console.log(this.state.operation)            this.setState({answer: this.A+this.B}, console.log(this.state.answer))            this.setState({operand: this.state.answer, operand2: '', operation: ''})            break        case "*":            console.log(this.state.operation)            this.setState({answer: this.A+this.B}, console.log(this.state.answer))            this.setState({operand: this.state.answer, operand2: '', operation: ''})            break        case "÷":            console.log(this.state.operation)            this.setState({answer: this.A+this.B}, console.log(this.state.answer))            this.setState({operand: this.state.answer, operand2: '', operation: ''})            break        default:            //    }}計(jì)算應(yīng)用和控制臺(tái)日志的屏幕截圖,顯示 0 作為 A+B 的輸出(A=15,B=12你能幫忙嗎,我在這里做錯(cuò)了什么?
查看完整描述

1 回答

?
滄海一幻覺

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

你的錯(cuò)誤就在這里

this.setState({answer: (this.A+this.B).toString()}, console.log(this.state.answer))

當(dāng)您嘗試顯示 this.state.answer 時(shí),答案尚未更新。

嘗試將控制臺(tái).log傳遞給 cb:

this.setState({answer: (this.A+this.B).toString()}, () => console.log(this.state.answer))



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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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