这是我的前端
我得到的变量的值interestRate,并monthlyPayment从API。我只想在前端设置这些值。这是我的代码:
class Display extends Component {
componentDidMount() {
this.calculateAPR();
}
componentDidUpdate(prevProps) {
this.calculateAPR();
}
calculateAPR = () => {
let x = JSON.parse(localStorage.getItem('amount'));
a=x[0].amount;
t=x[0].years;
fetch("https://herokuapp.com/interest?amount="+a+"&numMonths="+t)
.then(res => res.json())
.then(
(result) => {
//console.log(result);
interestRate = result.interestRate;
monthlyPayment = result.monthlyPayment.amount;
console.log(interestRate, monthlyPayment);
},
)
this.calculateMonthlyRepayment(monthlyPayment);
this.percentageAPR(interestRate);
};
calculateMonthlyRepayment = (z) => {
return <p>${z}</p>;
};
percentageAPR = (z) => {
return <p>{z * 100}%</p>;
};
render() {
return (
<div className="flex">
<DisplayChild func={this.percentageAPR()} text="interest rate" />
<DisplayChild
func={this.calculateMonthlyRepayment()}
text=" monthly repayment"
/>
</div>
);
}
}
这是我显示这些值的地方,但这些值没有显示:
const DisplayChild = ({ func, text }) => {
return (
<span>
{func} <small>{text}</small>
</span>
);
};
莫回无
相关分类