Muh*_*hil 12 javascript rest reactjs strapi
{\nid: 2,\nattributes: {\ntitle: \xe2\x80\x98Test Title\xe2\x80\x99,\nbody: \xe2\x80\x98Test Body\xe2\x80\x99,\ndate: null,\ncreatedAt: \xe2\x80\x982021-11-30T20:52:09.206Z\xe2\x80\x99,\nupdatedAt: \xe2\x80\x982021-11-30T20:57:26.724Z\xe2\x80\x99,\npublishedAt: \xe2\x80\x982021-11-30T20:57:26.720Z\xe2\x80\x99\n}\nRun Code Online (Sandbox Code Playgroud)\n
小智 21
我自己也经历过这样的挣扎。我无法使用 Strapi 4 和 Nuxtjs 来使用他们的查询引擎和实体引擎。
\n要在 API 中显示图像或(动态)组件,请务必使用:
\nhttp://localhost:1337/api/[your api]?populate=*\nRun Code Online (Sandbox Code Playgroud)\n不幸的是,它们默认不显示。他们说:
\n默认情况下,我们不会在 Strapi 中自动填充任何字段,因为不这样做的目的主要是为了提高性能,而且如果角色没有\xe2\x80\x99t 有权访问相关内容类型上的查找控制器,那么也是与 v4 中一样的安全性无法填充它。
\n在 v4 上进行此更改是不可能的,因为这将被视为破坏,但我们愿意接受超出默认值的功能请求。
\n如果您想对具有嵌套组件的动态区域执行此操作,您应该执行以下操作:
\nhttp://localhost:1337/api/[your api]?populate=ImagesRepeater.image\nRun Code Online (Sandbox Code Playgroud)\n这ImageRepeater是块的名称,image也是组件内部的字段。
如果您想实现相同的目标而不在 URL 中填充此内容,您可以在此处找到更多文档:https: //docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest /populate-fields.html#population
\n小智 3
Strapi 4 要求您填写您的请求(请参阅:填写文档)
可能看起来像这样(对于 2 级人口):
// populate request
const qs = require('qs')
const query = qs.stringify(
{
populate: {
Title: {
populate: ['Image']
}
}
},
{
encodeValuesOnly: true
}
)
// get id
const id = yourId
// get rquest
const Response= await axios.get(
`http://localhost:1337/api/[your api]/${id }/?${query}`
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17500 次 |
| 最近记录: |