数据预取接入:prefetchDetail一直为9
71 浏览2025年05月20日作者:comeMoney

抖音小程序接入数据预取的方案

  1. 在抖音官网上的性能优化那里对接的数据预取的问题:
    1. 项目是使用uni-app框架打包运行的抖音小程序
    2. 其中${token}是存在Storage里边的,只测试传了一个token,一直报prefetchDetail: 9,prefetchInfo: {mismatchReason: "no prefetch cache"}
    3. 而且在app.vue里onLanuch的时候token可以打印出来有值的,但是一直报"no prefetch cache"
    4. 如果在prefetchRules把token写死,就可以预取,只要去本地的就不行,但是本地Storage的token打印是一直有值的
  2. 猜测方向和疑问:
    1. 手机在抖音开发者工具真机调试,每次扫码我看在onLAnuch的token都是可以打印出来的。是否跟每次扫码storage的值取不到
  3. 有没有大佬遇到过的,希望大佬伸出援手帮忙解决一下
这是代码片段:
// app.json ,uni-app打包完需要手动补全数据prefetchRules
"prefetchRules": {
    "pages/index/index": {
      "https://new-media-1.kureader.com/miniapp/v1/content/home-config": {
        "method": "GET",
        "header": {
          "app-id": "tt91aee7130e98ce1f01",
          "authorization": "Bearer ${token}",
          "content-type": "application/json",
          "project": "reader_paid_dyminiapp"
        },
        "hitPrefetchExtraRules": {
          "requiredHeaderKeys": [
            "authorization",
            "app-id",
            "project",
            "content-type"
          ]
        }
      }
    }
  }
// 其中token是存在Storage里边的,只测试传了一个token
// http.ts的参数设置usePrefetchCache为true
{
  url,
	data,
	method: method || 'POST',
	header: {
 	   'content-type': contentType,
 	   ...header
	},
	// 主要是开启数据预取
	usePrefetchCache: true,
	timeout: 10000,
  ...
}
  
开启后用真机调试,一直报prefetchDetail: 9,找不到原因,且抖音开发者平台没有解决案例


最后一次编辑于 2025 年 05 月 20 日
共 1 条评论

相关问答

专题推荐

热门文章

热门问答