问题描述
this.state.basecurrency是“ USD”。我正在尝试缓存提取所返回的数据,但是在调用该函数时出现此错误:未处理的拒绝(TypeError):无法设置未定义的属性“ USD”。我看不到我所缺少的内容,在我看来,缓存应该只将生成的信息放入美元中。
calculatevalue = () => {
const howmuch = Number(this.state.basecurrencyamount);
const howmuch2 = parseFloat((this.state.basecurrencyamount));
if (isNaN(howmuch) || isNaN(howmuch2)) {this.setState({othercurrencyamount:""}); return};
fetch(`https://api.exchangeratesapi.io/latest?base=${this.state.basecurrency}`)
.then(response=>response.json())
.then(data=>{
this.cached[this.state.basecurrency] = {rates: data.rates,timestamp:Date.Now()};
this.setState({othercurrencyamount:data.rates[this.state.othercurrency]*this.state.basecurrencyamount})
});
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)