将prop值作为查询字符串传递给sveltekit端点



我正试图将一个prop值从文本输入字段传递到Svltekit端点,但我不知道如何传递它。

我的onsubmit运行此功能

const handleSubmit = () => {
promise = getData();
}

它调用一个函数,通过sveltekit端点从外部API获取数据:

async function getData() {
const response = await self.fetch('api/address.json');
const addressdata = await response.json()
if (response.ok) {
return addressdata;

} 
}

终点看起来像这个

export async function get({ }) {
const baseurl = 'https://myaddressapi/?postcode=xxxxxx'
const res = await fetch(baseurl, {
method: 'GET',
headers: {'Accept': 'application/json',
'APIKey': 'mykey'}
})
const data = await res.json()
if (res.ok) {
return {
status: 200,
body: data
}
}
return {
status: res.status,
error: new Error('This is an error')
}
}

我想做一些类似的事情:

const response = await self.fetch('api/address.json', {props:{searchInput}});

然后在端点上捕获:

export async function get(request, props)
const baseurl = 'https://myaddressapi/?postcode='
const url = `${baseurl}${props}`

我试着看了一下文档,但似乎无法使其发挥作用。有什么建议吗?

我重新阅读了文档,需要将邮政编码作为ID传递到端点,该端点现在正在工作。

更多信息请点击这里-https://kit.svelte.dev/docs/routing#endpoints

最新更新