阿修罗
阿修罗
  • 发布:2022-01-07 08:37
  • 更新:2022-01-07 11:19
  • 阅读:1079

vue3 getApp() 微信小程序

分类:nvue

main.js
app.config.globalProperties.$http = (url, data, method='get') => {
return new Promise((resolve, reject) => {
resolve('http ok');
})
};

========================================================
index.nuve
getApp().$http().then(res => {
console.log( res )
})

开发版本 3.3.5
APP 安卓

运行在APP里正常获取
发布到微信小程序时,提示错误

vendor.js? [sm]:3592 TypeError: getApp(...).$http is not a function
at Proxy.onShow (index.js? [sm]:21)
at callWithErrorHandling (vendor.js? [sm]:3534)
at callWithAsyncErrorHandling (vendor.js? [sm]:3542)
at Array.hook.weh.hook.weh (vendor.js? [sm]:2085)
at invokeArrayFns (vendor.js? [sm]:4687)
at Proxy.callHook (vendor.js? [sm]:4790)
at Li.mpOptions.<computed> [as onShow] (vendor.js? [sm]:4825)
at Li.<anonymous> (WASubContext.js?t=wechat&s=1641514275792&v=2.21.3:2)
at Li.n.callPageLifeTime (WASubContext.js?t=wechat&s=1641514275792&v=2.21.3:2)
at WASubContext.js?t=wechat&s=1641514275792&v=2.21.3:2(env: Windows,mp,1.05.2112301; lib: 2.21.3)

=========================

如果 index.nvue 里改为
this.$http().then(res => {
console.log( res )
})
就小程序里正常,APP里报错
TypeError: this.$http is not a function

在H5 页面,两种情问都能正常显示

2022-01-07 08:37 负责人:无 分享
已邀请:
y***@youjiuzs.com

y***@youjiuzs.com

条件编译一下

阿修罗

阿修罗 (作者)

已找到问题

APP H5时,
在nvue 页面里,可以用 getApp().$http 调用,不能使用 this.$http

微信小程序里
在nvue 页面里,可以用 this.$http 调用,不能使用 getApp()..$http

在vue页面里 this.$http 都可以调用 微信小程序里 getApp()..$http 报错

该问题目前已经被锁定, 无法添加新回复