4***@qq.com
4***@qq.com
  • 发布:2023-02-24 11:27
  • 更新:2023-02-24 17:01
  • 阅读:728

【报Bug】vue3模式下globalData问题

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 3.7.3

浏览器平台: Edge

浏览器版本: 110.0.1587.50 (正式版本) (64 位)

项目创建方式: HBuilderX

示例代码:
text.js  
let myHost = "http://192.168.2.103:8085/";  
let myws = "ws://192.168.2.103:9326";  
let common = {  
    webSocketUrl: myws,  
    loginUrl: myHost + "login"  
}  
export default  common ;  
----------------------------------------------------------------------------------------  
App.vue  
import COMMON from './common/js/text.js'  
export default {  
        globalData: {  
                account: "",  
            common: COMMON  
        },  
----------------------------------------------------------------------------------------  
index.vue  
onLoad() {  
        console.log(getApp().globalData)  
        console.log(getApp().globalData.common)  
    console.log(getApp().globalData.common.loginUrl)   //此处undefined  
}  

操作步骤:
text.js  
let myHost = "http://192.168.2.103/";  
let myws = "ws://192.168.2.103";  
let common = {  
    webSocketUrl: myws,  
    loginUrl: myHost + "login"  
}  
export default { common };  
----------------------------------------------------------------------------------------  
App.vue  
import COMMON from './common/js/text.js'  
export default {  
        globalData: {  
                account: "",  
            common: COMMON  
        },  
----------------------------------------------------------------------------------------  
index.vue  
onLoad() {  
        console.log(getApp().globalData)  
        console.log(getApp().globalData.common)  
    console.log(getApp().globalData.common.loginUrl)   //此处undefined  
}  

预期结果:

正常打印数据

实际结果:

console.log(getApp().globalData.common.loginUrl) //此处undefined

bug描述:

在vue3模式下,globalData中引入js文件中的对象后,在getApp().globalData中只能点出这个整体的对象,无法点出对象中的属性。

2023-02-24 11:27 负责人:无 分享
已邀请:
DCloud_UNI_WZF

DCloud_UNI_WZF

测试未复现该问题,检查下代码逻辑,如确认框架问题,提供测试工程,谢谢

要回复问题请先登录注册