如何在放置参数[?]的位置使用getData函数中的url和stateObj参数?
function getData(url, stateObj) {
fetch(arguments[0])
.then(res => res.json())
.then(res => {
this.setState({ arguments[1]: res.results });
});
}
答案 0 :(得分:3)
function getData(url, stateObj) {
fetch(url)
.then(res => {
return res.json();
})
.then(res => {
this.setState({ [stateObj]: res.results });
})
}
上的括号表示法部分