快手小程序踩坑——首屏数据预取踩坑记录
快手小程序踩坑——首屏数据预取踩坑记录
快手首屏数据预取官方文档:https://open.kuaishou.com/docs/develop/frame/prefetch.html#_2-request-api-%E9%80%82%E9%85%8D
踩坑记录:
res.isPrefetch打印结果是 false,
res.prefetchInfo打印结果是 request url has no matching prefetch cache
并且如果app.json中的${id}是具体的值,会为true
app.json代码
"pages/xx/xx": {"https://ks.xx.com/xx/xx/xx?id=${id}": {"method": "GET","dataType": "json","responseType": "text","hitPrefetchExtraRules": {"requiredQueryKeys": ["id"]}}}
解决踩坑:
在快手小程序中,预加载的触发需要满足以下条件:
跳转的页面路径和参数必须与预加载配置的路径和参数名字一致
我的变量id是通过上一个页面参数拿到的,要改变让一个页面传递的id名即可,之后就返回的是true。
goToRecommend(e) {const item = e.currentTarget.dataset.item;ks.navigateTo({ url: `/pages/xx/xx?id=${item.id}`});}