handleClickInc(e){ let now=new Date(); let Year = now.getFullYear(); let Month = now.getMonth()+1; let Date = now.getDate(); let Hour = now.getHours(); let Min = now.getMinutes(); let Sec = now.getSeconds(); let mess_now=Year + "年" + Month + "月" + Date + "日" + Hour + ":" + Min + ":" + Sec; let mess=mess_now+"に"+this.state.types[e.target.name].roletype+"を1増やしました。"; const name=e.target.name; let copy_types=this.state.types.slice(); copy_types[name].count+=1; this.setState((prevState,props)=>({types:copy_types})); this.setState({mess:mess}); }
reactの練習でクリックカウンタを作っています。増ボタンを押したときイベントハンドラ内で日時を取得して、メッセージ「〇年〇月〇日〇時〇分〇秒に〇〇を1増やしました。」を作成するため、上記のコードを書いたのですが、
react-dom.production.min.js:17 Uncaught TypeError: Date is not a constructor at App.handleClickInc (<anonymous>:102:14) at Object.onClickInc (<anonymous>:223:22) at MyState.onSubmitInc (<anonymous>:286:15) at Object.sh (react-dom.production.min.js:164)
上記のエラーが出ます。どうしたらよいかわかりません。何かインポートする必要があるんでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/05 01:49