mou*_*777 7 javascript typescript fetch-api
我在 fetch 函数的“fetchUrl”参数中收到以下错误
'string | 类型的参数 undefined' 不可分配给'RequestInfo' 类型的参数。
在这个函数中
let fetchUrl = getBaseUrlNative( process.env.APP_DATA, `/v2/marketing/app/file/${file}?cookies=${cookieSess}&expires=${Date.now()}`)
await fetch(fetchUrl, { method: 'get' , cache:"no-store" , headers: {
'Cache-Control': 'no-cache'
}})
.then(res => res.blob())
.then(res => { .......
Run Code Online (Sandbox Code Playgroud)
getBaseUrlNative 是
export const getBaseUrlNative = (eUrl : string | undefined, ext : string | undefined) => {
try {
if (!eUrl) throw new Error("Error .")
return ext ? eUrl+ext : eUrl;
} catch (err) {
console.log(err)
}
}
Run Code Online (Sandbox Code Playgroud)
小智 -3
在 fetch 函数中使用any数据类型来禁止类型检查。
let fetchUrl = getBaseUrlNative( process.env.APP_DATA, `/v2/marketing/app/file/${file}?cookies=${cookieSess}&expires=${Date.now()}`)
await fetch(<any>fetchUrl, { method: 'get' , cache:"no-store" , headers: {
'Cache-Control': 'no-cache'
}})
.then(res => res.blob())
.then(res => { .......Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5021 次 |
| 最近记录: |