2***@QQ.COM
2***@QQ.COM
  • 发布:2025-04-07 21:56
  • 更新:2025-04-17 21:11
  • 阅读:303

【报Bug】uniapp main.js 注册全局全局属性错误

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 4.61

手机系统: Android

手机系统版本号: Android 14

手机厂商: 华为

手机机型: 11

页面类型: nvue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

App下载地址或H5⽹址: 1

示例代码:

main.js

import store from './store'
app.config.globalProperties.$adpid = "1111111111"
app.config.globalProperties.$store= store

component.nvue
console.log(123,123)
console.log(123, this.$adpid)

H5 能正常使用
app错报
reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught TypeError: (0 , import_vuex.createStore) is not a function
at (pages/tabBar/component/component.js.nvue:156:43)
at (pages/tabBar/component/component.js.nvue:570:3)

操作步骤:

1

预期结果:

1

实际结果:

1

bug描述:

main.js

import store from './store'
app.config.globalProperties.$adpid = "1111111111"
app.config.globalProperties.$store= store

component.nvue
console.log(123,123)
console.log(123, this.$adpid)

H5 能正常使用
app错报
reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught TypeError: (0 , import_vuex.createStore) is not a function
at (pages/tabBar/component/component.js.nvue:156:43)
at (pages/tabBar/component/component.js.nvue:570:3)

2025-04-07 21:56 负责人:无 分享
已邀请:
套马杆的套子

套马杆的套子 - 没有解决不了的问题,只有解决不完的问题

你这个是vue3的写法
看你用的是vue2吧
你要想挂载,Vue.prototype.$adpid = "1111111111"

这样用用呢

恭喜n发财

恭喜n发财 - 恭喜恭喜恭喜你呀

我怎么感觉是vuex 的版本问题,注释下app.config.globalProperties.$store= store 应该不会报错了吧,看下你store怎么写的,估计用的是2.0

2***@QQ.COM

2***@QQ.COM (作者)

10:24:09.429 onLoad at pages/index/index.nvue:137
10:24:09.430 onShow at pages/index/index.nvue:167
10:24:09.675 onReady at pages/index/index.nvue:119
10:24:09.920 onLaunch at App.vue:7
10:24:10.042 onShow at App.vue:101

index.nuve 不可以使用 uni.$store.state
App.vue 不可以使用 uni.$store.state
非主页面 可以使用 uni.$store.state

应该是 主页面启动太快了

灳灳

灳灳 - 他很懒

vue3,在vue页面能取到globalProperties里面定义的变量,但在nvue页面,却直接显示的是undefined

要回复问题请先登录注册