【发布时间】:2021-06-09 21:13:39
【问题描述】:
已经为我的愚蠢问题感到抱歉,但谷歌搜索没有成功
如何在箭头函数中添加多个参数。我想在下面的函数中添加一些属性“props”。
const changeLocationHandler = async event => {
try {
let hasError = false;
let response = await fetch('http://localhost:5000/api/game/location', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + auth.token
},
body: {
}
});
const responseData = await response.json();
if (!response.ok) {
hasError = true;
}
if (hasError) {
alert(responseData.message);
}
} catch (error) {
alert(error)
}
}
它不接受类似的东西
const changeLocationHandler = async event props => {
或
const changeLocationHandler = props => async event => {
提前致谢
【问题讨论】:
-
(event, props) => { ... }javascript.info/arrow-functions-basics -
只有1个参数的函数可以缺少
() -
这样的问题通常由谷歌搜索回答,如“mdn 箭头函数”
-
对不起,问这个问题的人 - 正如我所说的那样,这将是一个愚蠢的问题,是的,我看到了 mdn 网页但不明白它。无论如何感谢您的回答,它现在可以工作了。
标签: javascript reactjs arrow-functions