Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taro H5 模式下,网络请求调用错误 #590

Closed
shiweifu opened this issue Dec 6, 2019 · 5 comments
Closed

Taro H5 模式下,网络请求调用错误 #590

shiweifu opened this issue Dec 6, 2019 · 5 comments

Comments

@shiweifu
Copy link

shiweifu commented Dec 6, 2019

Taro 运行在 H5 模式下:

npm run dev:h5

执行任意网络请求,报错:

index.js?4e85:62 Error: wx is not defined [N/A GET https://xxxxxxxxxx.com/1.1/classes/Category]
    at eval (av-weapp.js?29a0:1964)
    at tryCatch (av-weapp.js?29a0:7541)
    at invokeCallback (av-weapp.js?29a0:7541)
    at eval (av-weapp.js?29a0:7474)
    at flush (av-weapp.js?29a0:7440)
eval @ index.js?4e85:62
tryCatch @ av-weapp.js?29a0:7541
invokeCallback @ av-weapp.js?29a0:7541
publish @ av-weapp.js?29a0:7541
publishRejection @ av-weapp.js?29a0:7541
flush @ av-weapp.js?29a0:7440
setTimeout (async)
eval @ av-weapp.js?29a0:7440
asap @ av-weapp.js?29a0:7373
then @ av-weapp.js?29a0:7474
setHeaders @ av-weapp.js?29a0:1820
request @ av-weapp.js?29a0:1925
_createRequest @ av-weapp.js?29a0:14998
find @ av-weapp.js?29a0:15112
onSubmit @ index.js?4e85:57
onSubmit @ index.js?a709:10
onSubmit @ index.js?febc:74
dispatchEvent @ index.esm.js?eb37:584
eventHandler @ index.esm.js?eb37:622

应该是当前运行环境识别成了微信小程序,然后 ajax 请求调用成了 wx 相关的网络请求函数。

请求修复

@leeyeh
Copy link
Contributor

leeyeh commented Dec 8, 2019

SDK 是如何安装引入的呢?

@shiweifu
Copy link
Author

通过 npm 引入的。

	"dependencies": {
		....
		"leancloud-storage": "^4.0.1",
}
import AV from "leancloud-storage/dist/av-weapp.js";

在小程序下一切正常。

@leeyeh
Copy link
Contributor

leeyeh commented Dec 12, 2019

Taro 并不支持根据不同的平台加载对应的 SDK : #558 (comment)

因此如果要编译到 H5,需要 import AV from "leancloud-storage";

@leeyeh
Copy link
Contributor

leeyeh commented Mar 23, 2020

自 v4.5.0 起,SDK 开放了配置 Adapter 来支持不同的平台。对于 Taro,可以自行使用 taro 提供的 API(几乎与微信小程序一致)来实现 adapter 从而实现所有平台使用一套代码,无需从不同的路径引入不同平台的 SDK。

@shiweifu
Copy link
Author

shiweifu commented Mar 29, 2020

自 v4.5.0 起,SDK 开放了配置 Adapter 来支持不同的平台。对于 Taro,可以自行使用 taro 提供的 API(几乎与微信小程序一致)来实现 adapter 从而实现所有平台使用一套代码,无需从不同的路径引入不同平台的 SDK。

好的,谢谢回复。我升级一下 SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants