我正在使用 APISauce 创建对我的服务器的发布请求。
这很好用,并且id, title and desc
是我在函数中传递的变量。return client.post("/workout", { userId: id, title: title, description: desc, });
描述是可选的,如果值为空,我不能发布它。
我可以这样做-
if (desc){
return client.post("/workout", {
userId: id,
title: title,
description: desc,
});
}else
return client.post("/workout", {
userId: id,
title: title,
});
但这有很多重复,所以我只想检查是否有更有效的方法来做到这一点?我可以检查 JSON 对象中的描述字段吗?