提问人:Jay0813 提问时间:9/12/2023 最后编辑:Brian Tompsett - 汤莱恩Jay0813 更新时间:9/12/2023 访问量:59
使用查询字符串进行筛选在 sveltekit 中不起作用。如何解决这个问题?
Filter using query string is not working in sveltekit. How to solve this?
问:
我用了 sveltekit, 我实现了一个过滤器,该过滤器具有带有输入和 searchBtn 的选择框。 下面是按钮事件:
async function handleSearchEvent(
event: CustomEvent<{ role: string; category: string; input: string }>
) {
const { role, category, input } = event.detail;
goto(`?category=${category}&role=${role}&project_id=${_projectId}&nick_name=${input}&page=1`);
}
这是我的服务器端代码,它+page.server.ts
import { error } from '@sveltejs/kit'; // import { fetchUserData, isFailure } from '$lib/api';
import { fetchSearchUser, fetchUsersData, isFailure, type Users } from '$lib/api';
import resolveSearchParam from '$lib/utils/resolveSearchParam.js';
type LoadResponse = {
users: Users;
};
type LoadInput = {
url: {
href: string;
};
params: {
[key: string]: string;
};
};
/** @type {import('./$types').PageLoad} */
export async function load({ params, url }: LoadInput): Promise<LoadResponse> {
console.log('clicked')
const pageNum = resolveSearchParam(url.href, 'page', '1');
const category = resolveSearchParam(url.href, 'category', '');
const role = resolveSearchParam(url.href, 'role', '');
const nickname = resolveSearchParam(url.href, 'nick_name', '');
const projectId = params.project_id;
const result = await fetchSearchUser(role, nickname, category, pageNum, projectId);
if (isFailure(result)) {
throw error(404, {
message: 'Failed to get users',
code: 'NOT_FOUND'
});
}
console.log(result.data)
return {
users: result.data
};
}
当我单击searchBtn时,我可以检查日志和过滤数据,但不能在屏幕上更新。 问题是什么以及如何解决?
欢迎任何建议。
答: 暂无答案
评论