Vue3调用接口时过滤传参数据中的空字段
以及查询字符串格式的传参
export const userListService = (pageRequest, searchData) => {
const filteredSearchData = Object.entries(searchData)
.filter(([key, value]) => value !== null && value !== undefined && value !== '')
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
const searchParams = new URLSearchParams(filteredSearchData)
return request.get(
`/user?pageNum=${pageRequest.pageNum}&pageSize=${pageRequest.pageSize}${
searchParams.toString() ? '&' + searchParams.toString() : ''
}`
)
}