在vite项目中加载cesium3d地图时,地图没有展示,F12显示有报错信息:
Uncaught (in promise) TypeError: Failed to execute 'createImageBitmap' on 'Window': The provided value is not of type '(Blob or HTMLCanvasElement or HTMLImageElement or HTMLVideoElement or ImageBitmap or ImageData or OffscreenCanvas or SVGImageElement or VideoFrame)'.
报错信息提示,提供的值不是类型Blob或HTMLCanvasElement balabala,说明请求的数据格式有问题,在network中发现对cesium请求数据http状态是304,而且发起者是mock。 解决方法就是要么禁掉mock的使用,要么修改一下mock的源码。在代码项目//node_modules/mockjs/dist/mock.js 大约在8362行处进行修改:
// 原生 XHR
if (!this.match) {
//添加此行代码
this.custom.xhr.responseType = this.responseType
this.custom.xhr.send(data)
return
}