Sanity内容不显示求助:自定义JavaScript Schema无法展示
解决Sanity Schema内容无法在站点显示的方案
修正Schema拼写错误
你的testimonials Schema里图片字段的配置项拼写有误,option应改为复数options,这个错误会导致Schema解析异常。修正后的代码如下:export default { name: 'testimonials', title: 'Testimonials', type: 'document', fields: [ { name: 'name', title: 'Name', type: 'string', }, { name: 'company', title: 'Company', type: 'string', }, { name: 'imageurl', title: 'ImgUrl', type: 'image', options: { hotspot: true, } }, { name: 'feedback', title: 'Feedback', type: 'string', }, ], }确认已创建并发布对应文档
即使Schema正确导入,也需要登录Sanity Studio手动创建至少一条Testimonials类型的文档并发布,站点才能获取到可展示的内容。重启Sanity Studio服务
修改Schema后,关闭当前运行的Studio终端进程,重新执行sanity start,确保新的Schema配置加载生效。检查站点端GROQ查询是否正确
确保站点获取数据的GROQ查询正确指定文档类型,且字段匹配,尤其是图片字段需要嵌套获取资源链接。示例查询:*[_type == "testimonials"]{ name, company, feedback, imageurl{asset->{url}} }验证Schema注册状态
执行sanity schema list命令,确认testimonials类型已被正确注册到Sanity项目中。
内容的提问来源于stack exchange,提问作者Ahmed Elbaz
相关产品推荐
相关产品推荐

