retrocode
retrocode
  • 发布:2025-06-09 15:39
  • 更新:2025-06-12 09:22
  • 阅读:125

【报Bug】uni.preloadPage预加载的nvue页面内 uni.getSystemInfoSync 报错 e.$getAppWebview is not a function

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 11

HBuilderX类型: 正式

HBuilderX版本号: 4.66

手机系统: Android

手机系统版本号: Android 7.0

手机厂商: 商米

手机机型: 商米

页面类型: nvue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:
<template>  
  <view><button @click="ttttttt">打开预加载页</button></view>  
</template>  
<script setup>  
import { onReady } from '@dcloudio/uni-app'  
const ttttttt = () => uni.navigateTo({ url: '/pages/test/test' })  
onReady(() => uni.preloadPage({ url: '/pages/test/test' }))  
</script>
<template>  
  <view><button @click="ttttttt">测试</button></view>  
</template>  
<script setup>  
const ttttttt = () => {  
  console.log('onShow1')  
  console.log(uni.getDeviceInfo())  
  console.log(uni.getSystemInfoSync())  
  console.log('onShow2')  
}  
</script>

预期结果:
15:38:00.099 onShow1 at pages/test/test.nvue:6  
15:38:00.099 [Object] {"brand":"sunmi","deviceBrand":"sunmi","deviceModel":"K2_C","devicePixelRatio":1,"deviceId"...} at pages/test/test.nvue:7  
15:38:00.122 [Object] {"SDKVersion":"","appId":"__UNI__158359C","appLanguage":"zh-Hans","appName":"nvue测试preloadP...} at pages/test/test.nvue:8  
15:38:00.122 onShow2 at pages/test/test.nvue:9

实际结果:
15:36:01.657 onShow1 at pages/test/test.nvue:6  
15:36:01.674 [Object] {"brand":"sunmi","deviceBrand":"sunmi","deviceModel":"K2_C","devicePixelRatio":1,"deviceId"...} at pages/test/test.nvue:7  
15:36:01.688 [Vue warn]: Unhandled error during execution of native event handler  
 at <ButtononClick=fn<ttttttt>>  
 at <Test__pageId=3__pagePath="pages/test/test"__pageQuery={}>  
15:36:01.688 TypeError: e.$getAppWebview is not a function

bug描述:

安卓端 被 uni.preloadPage 预加载的 nvue 页面内使用 uni.getSystemInfoSync api 报错 e.$getAppWebview is not a function
4.66 版本使用标准基座可复现

2025-06-09 15:39 负责人:无 分享
已邀请:
DCloud_UNI_LXH

DCloud_UNI_LXH

只有使用 getSystemInfoSync 的时候会报这个错误?除了安卓端,其他端会报错吗?

  • retrocode (作者)

    没有测试其他端, 不过我测试发现nvue里预加载的页面的 onLoad 内 getCurrentInstance() 会报错 ReferenceError: getCurrentInstance is not defined ,


    <template>  
    <view><button @click="ttttttt('click')">测试</button></view>
    </template>
    <script setup>
    import { onLoad, onReady, onShow } from '@dcloudio/uni-app'
    const ttttttt = str => {
    console.log(`${str} start`)
    console.log(`${str} DeviceInfo`, uni.getDeviceInfo())
    console.log(`${str} SystemInfoSync`, uni.getSystemInfoSync())
    console.log(`${str} end`)
    }
    onReady(() => ttttttt('onReady'))
    onShow(() => ttttttt('onShow'))
    onLoad(o => {
    const instance = getCurrentInstance()?.proxy
    eventChannel = instance.getOpenerEventChannel()
    eventChannel.on('test', res => {})
    ttttttt('onLoad')
    })
    </script>

    2025-06-09 18:17

  • retrocode (作者)

    这是我今天适配 预加载时碰到的, 基本都是原nvue页面正常工作. 仅仅执行了预加载, 这些函数就不存在, 或者干脆报错了

    2025-06-09 18:19

  • DCloud_UNI_LXH

    回复 retrocode: 建议结合 onShow 生命周期来判断 onReady、onLoad 中的代码是否执行

    2025-06-10 17:45

  • retrocode (作者)

    回复 DCloud_UNI_LXH: 你好, 我上传了复现项目, 安卓使用标准基座就可以复现.

    2025-06-12 09:18

  • retrocode (作者)

    回复 DCloud_UNI_LXH: 你好, 如果NVUE停止维护了, 这个bug不打算修复的话, 能否告知一下大致是什么类的问题, 会影响哪些系统API, 我们这边想办法规避, nvue不开源我们也没法自己定位问题,

    2025-06-16 10:20

  • DCloud_UNI_LXH

    回复 retrocode: 应该是 preLoadPage 触发了 onLoad 等生命周期,生命周期中调用了 getSystemInfoSync,而 getSystemInfoSync 中调用了需要 page 初始化后才可用的内容,可以结合 onShow 和其他生命周期来判断是否执行相关逻辑。preLoadPage 会触发 onLoad,但是不会触发 onShow

    2025-06-16 11:25

  • retrocode (作者)

    回复 DCloud_UNI_LXH: 是这样的, 你可能没有理解我的意思, 我在楼下附件中上传了demo, 你实机跑一下就可以理解了, 主要问题就是, getSystemInfoSync 在预加载时的onload和onready 生命周期函数内是可以正常执行的,


    但是真正打开页面后, 在页面内通过 onshow 或 手动点击按钮执行对应函数, 就会报错.


    如果只是单纯的 onload时报错还好, 现在是只有onload时是好着的.

    2025-06-16 15:40

retrocode

retrocode (作者) - 现已加入旺旺大礼包全家桶

经测试, 的确是有问题的, 我上传了复现项目, 你们可以测试一下. 安卓使用标准基座就可以

要回复问题请先登录注册