【发布时间】:2021-04-07 04:56:30
【问题描述】:
所以最终我想为一个可选参数传入一个值,但“未定义”作为一个字符串被插入,而不是像我想要的那样表现。我在这里想念什么?默认情况下,路由应该是 /api/todo/get/ 我知道我可以不使用“showAll”,但要避免尴尬。谢谢。
const getTodos = (showAll = undefined): Thunk<Promise<void>> => (dispatch) => {
dispatch(setTodos([]));
return axios.get(`/api/todo/get/${showAll}`).then((res) => {
dispatch(setTodos(res.data));
});
};
router.get("/get/:includeCompleted?", (req: Request, res: Response) => {
const includeCompleted = req.params.includeCompleted;
console.log(req.params.includeCompleted);
return database
.raw<Todo[]>(
`
SELECT *
FROM todo
WHERE :includeCompleted = 1 OR completedDate IS NULL
`,
{includeCompleted: includeCompleted ? 1 : 0}
)
.then((data) => res.status(StatusCodes.OK).json(data));
});
【问题讨论】:
标签: typescript api axios