为什么sl不保存在strapi中?

发布于 2025-02-06 06:38:05 字数 404 浏览 2 评论 0原文

有一个视频内容类型字段,其中有一个链接slug,当创建新视频时,在GET请求中,我们会得到一个无效的sl。告诉我怎么了。没有安装slugify

docs

“

“

there is a video content type field in which there is a link slug, and when a new video is created, in the get request we get a null slug. tell me what's the matter. didn't install slugify

docs

strapi img

get img

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2025-02-13 06:38:05

在attrapi中呼叫API呼叫之后,请遇到{slug:null}吗?

好的,这是我所做的,

我根据我的表单字段之一(例如:名称字段)在发布请求之前做了一个变量。
我的FormValues是一个对象,具有

formValues = {name:“ whthing”,decsription:“ whything”}

制作变量:

const slug = formValues.name.name.name.split(split( “”).join(“ - ”) +“ - ” + Math.random();

现在我们可能拥有相同的名称,所以这就是为什么我使用随机值(您可能想使用UUID或类似的东西那)

然后您像这样发送

const res = await axios.post(`${API_URL}/api/events`,{...formValues, slug }); 
// you may not need to send an object with the shape like this 
// but the point is you concat your custom slug to the object you want to send

通知我正在添加Frontend的自定义slug,这是随机的,但基于其中一个字段,但这并不重要,现在Strapi确实做到了没有关于这个常见问题的任何文档,最好的解决方案可能是使用strapi-plugin-slugify,但是如果这对您不起作用,您可以随意使用我的解决方案

getting stuck at getting {slug : null} after api call in strapi?

ok, this is what I did

I made a variable before POST request based on one of my form fields (eg:name field)
my formValues is an object with values of form fields like this

formValues = {name:"whatever" , decsription:"whatever"}

make a variable:

const slug = formValues.name.split(" ").join("-") + "-" + Math.random();

now we might have same names, so that's why I used a random value (you might want to use uuid or something like that)

then you send it like this

const res = await axios.post(`${API_URL}/api/events`,{...formValues, slug }); 
// you may not need to send an object with the shape like this 
// but the point is you concat your custom slug to the object you want to send

notice I'm adding a custom slug from frontend which is somehow random but based off of one of the fields, but it doesn't really matter, right now strapi does not have any documentation about this common problem, it seems like the best solution might be usingstrapi-plugin-slugify but if that didn't work for you feel free to use my solution

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文