我的函数:
export const getStrapiUrl = (path): string => {
if (path == null) {
return "";
}
console.log(path);
return `${
path.startsWith("/", 1) ? process.env.NEXT_PUBLIC_STRAPI_API_URL : ""
}${path}`;
};
来自控制台的错误消息:
{ url:'/uploads/work_with_74e76d4826.png‘}
error - utils\get-strapi-url.ts (7:9) @ getStrapiUrl
TypeError: path.startsWith is not a function
5 | console.log(path);
6 | return `${
> 7 | path.startsWith("/", 1) ? process.env.NEXT_PUBLIC_STRAPI_API_URL : ""
| ^
8 | }${path}`;
9 | };
10 |
发布于 2021-12-03 10:58:15
根据输出{ url: '/uploads/work_with_74e76d4826.png' }
,path
不是一个字符串,它是一个对象。但是,您可以提取其中的url
部分:
return `${
path.url.startsWith("/", 1) ? process.env.NEXT_PUBLIC_STRAPI_API_URL : ""
}${path.url}`;
https://stackoverflow.com/questions/70213104
复制相似问题