- 发布:2024-12-31 14:11
- 更新:2024-12-31 14:11
- 阅读:28
【报Bug】鸿蒙 next - uni.scanCode 扫码之后再通过 uni.request 发起请求会有较大几率失败
产品分类: uni小程序SDK
手机系统: 全部
页面类型: vue
SDK版本号: @dcloudio/uni-app-runtime(V2.3.18)
测试过的手机:
示例代码:
onScanClick() {
uni.scanCode({
scanType: ['qrCode', 'barCode'],
success: (res) => {
// 不用管返回的值,都有几率复现
const code = res.result;
console.log('扫码成功');
this.doHttpRequest('hello');
}
})
},
doHttpRequest(code) {
console.log('开始请求...');
this.responseText = '';
uni.request({
url: "https://baidu.com",
method: 'POST',
data: `code=${code}`,
header: {
'content-type': 'application/x-www-form-urlencoded'
}
}).then((response) => {
// 请求成功
this.responseText = JSON.stringify(response.data);
}).catch(error => {
this.responseText = `请求失败, error: ${error.message}`;
}).finally(() => {
});
}
onScanClick() {
uni.scanCode({
scanType: ['qrCode', 'barCode'],
success: (res) => {
// 不用管返回的值,都有几率复现
const code = res.result;
console.log('扫码成功');
this.doHttpRequest('hello');
}
})
},
doHttpRequest(code) {
console.log('开始请求...');
this.responseText = '';
uni.request({
url: "https://baidu.com",
method: 'POST',
data: `code=${code}`,
header: {
'content-type': 'application/x-www-form-urlencoded'
}
}).then((response) => {
// 请求成功
this.responseText = JSON.stringify(response.data);
}).catch(error => {
this.responseText = `请求失败, error: ${error.message}`;
}).finally(() => {
});
}
操作步骤:
运行附件中的工程,点击 “打开 uni-app” -> 点击 “点我扫码后发起请求”,扫描任意二维码之后,在后续发起请求过程中,鸿蒙 uni sdk 有几率报错
运行附件中的工程,点击 “打开 uni-app” -> 点击 “点我扫码后发起请求”,扫描任意二维码之后,在后续发起请求过程中,鸿蒙 uni sdk 有几率报错
预期结果:
正常走完流程,扫码之后的请求能正常发起和响应
正常走完流程,扫码之后的请求能正常发起和响应
实际结果:
扫码之后,立即调用 uni.request 会有几率 鸿蒙 uni-sdk 报错
扫码之后,立即调用 uni.request 会有几率 鸿蒙 uni-sdk 报错
bug描述:
使用 uni 小程序 sdk 鸿蒙版 (2.3.18),在 vue 页面通过 uni.scanCode
扫码之后,通过 uni.request
发起请求,鸿蒙上的 uni-app-runtime sdk 会有几率报错:
[(-2:100000:active)] LocalStorage with ID 100000 not found!
[nweb_helper.cpp:664] web engine has been initialized
[(-2:100000:active)] LocalStorage with ID 100000 not found!
[default] [CallForNapi:3507] occur exception need return
[(native_api.cpp:1233)(napi_call_function)] pending exception when js function called, print exception info:
TypeError: Cannot read property userAgent of null
at anonymous (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-app-harmony/uni.api.ets:7546:27)
at anonymous (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3817:1)
at invokeApi (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3680:1)
at anonymous (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3694:1)
at anonymous (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:372:1)
at anonymous (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3480:1)
at anonymous (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3575:1)
at invokeCallback (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3503:1)
at invokeSuccess (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3730:1)
at resolve (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/sdk.js:3818:1)
at anonymous (oh_modules/.ohpm/@dcloudio+uni-app-runtime@2.3.18/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-app-harmony/uni.api.ets:8626:13)
附件内容描述:附件本身是 鸿蒙 DevEco Studio 工程,其中 Vue3Sample 是 uni-app 源码,uni-app 的产物已经以 wgt 的形式放在 DevEco Studio 工程中,在运行中被鸿蒙原生加载打开。