844736455@qq.com
844736455@qq.com
  • 发布:2019-10-15 10:02
  • 更新:2020-06-03 11:19
  • 阅读:1397

uni-app中的Blob对象

分类:uni-app

最近做的一个功能。后台返回了excel文件流,我调用Blob对象生成blob链接进行下载。但是遇到一个很奇怪的问题,在uni-app里提示我Can't find variable: Blob; 但是在PC端H5测试就是完全可行。
请问有人遇到过相同的问题或者类似的问题吗?
代码如下:
uni.request({
url: api.getExcel,
data: {
START_DATE: "2019-08-01 00:00:00",
END_DATE: "2019-08-05 23:00:00"
},
responseType: 'arrayBuffer',
success: res => {
var blob = new Blob([res.data]{type:'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet; charset=utf-8' })
var downloadElement = document.createElement('a')
var href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = 'result.xlsx'
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}
})

报错信息:
thirdScriptError
09:48:29.348 Can't find variable: Blob;at api request success callback function
09:48:29.348 success
09:48:29.348 app-service.js:3:417675
09:48:29.348 app-service.js:3:209453
09:48:29.348 app-service.js:3:95344
09:48:29.348 Xe@app-service.js:3:171618
09:48:29.348 app-service.js:3:281992
09:48:29.348 emit@app-service.js:3:202585
09:48:29.348 Ui@app-service.js:3:282502
09:48:29.348 app-service.js:3:283139
09:48:29.348 app-service.js:3:163721
09:48:29.348 subscribeHandler@app-service.js:3:1563
09:48:29.348 I@app-service.js:2:5382
09:48:29.349 Ct@app-service.js:2:28222
09:48:29.349 app-service.js:2:29189
09:48:29.349 call@[native code]
09:48:29.349 consume@weex-main-jsfm.js:1:1263
09:48:29.349 callback@weex-main-jsfm.js:1:11810
09:48:29.349 weex-main-jsfm.js:1:11031
09:48:29.349 weex-main-jsfm.js:1:11045

2019-10-15 10:02 负责人:无 分享
已邀请:

最佳回复

DCloud_UNI_GSQ

DCloud_UNI_GSQ

非H5端不是浏览器环境不支持 Dom、Bom 接口,没有 Blob 也没有 document 。
这在uni-app文档开篇的介绍中有说明:相关文档

772567199@qq.com

772567199@qq.com

同问,uniapp在真机上blob对象报错

筱依米

筱依米 - 我叫筱依米

以前我都没出现这个问题。没想到今天测试就出问题了; 你的是 Blob,而我是 result;尴尬的奇怪,请问你是如何解决的?

报错信息:
thirdScriptError
09:48:29.348 Can't find variable: result;at api request success callback function
09:48:29.348 success
09:48:29.348 app-service.js:3:417675
09:48:29.348 app-service.js:3:209453
09:48:29.348 app-service.js:3:95344
09:48:29.348 Xe@app-service.js:3:171618
09:48:29.348 app-service.js:3:281992
09:48:29.348 emit@app-service.js:3:202585
09:48:29.348 Ui@app-service.js:3:282502
09:48:29.348 app-service.js:3:283139
09:48:29.348 app-service.js:3:163721
09:48:29.348 subscribeHandler@app-service.js:3:1563
09:48:29.348 I@app-service.js:2:5382
09:48:29.349 Ct@app-service.js:2:28222
09:48:29.349 app-service.js:2:29189
09:48:29.349 call@[native code]
09:48:29.349 consume@weex-main-jsfm.js:1:1263
09:48:29.349 callback@weex-main-jsfm.js:1:11810
09:48:29.349 weex-main-jsfm.js:1:11031
09:48:29.349 weex-main-jsfm.js:1:11045

  • 844736455@qq.com (作者)

    没解决,放弃了。我觉得result不像是JS原有对象啊,是不是请求成功的回调里面你变量写错了

    2020-03-20 16:12

  • kysin

    回复 844736455@qq.com: 我也是,真机Can't find variable: Blob

    2020-04-12 01:14

  • 876426223@qq.com

    回复 kysin: 我也是同样的问题,请问解决了吗

    2020-04-13 14:07

  • 小系

    回复 876426223@qq.com: 巧了我也是

    2020-04-14 21:36

jf1796469699@163.com

jf1796469699@163.com

解决了吗

要回复问题请先登录注册