请问大佬们,为什么我这个加载不出来模型呢?
控制报错是这样的
更新过后
public
目录下的是不需要使用相对路径,直接用 /Cesium/model/scene.gltf
就行了。
而且这个报错信息并不是说路径后面会多个 /nJSON.parse
,这个是报错信息。转义之后的错误信息为:
Failed to load model: ../../../../../public/Cesium/parking_space_dae_V0.1.gltf
JSON.parse: unexpected character at line 1 column 1 of the JSON data
所以修改成这样就行了:
- const url = '../../../../../public/Cesium/model/scene.gltf'
+ const url = '/Cesium/model/scene.gltf'
const entity = viewer.value.entities.add({
position: position,
modal: {
uri: url,
minimumPixelSize: 1,
maxmunScale: 20000
}
}
Edit
看到了问题跟新,问题是静态资源的 /public
前缀不需要书写,所以修改为如下即可:
- const url = '/public/car/parking_space_dae_V0.1.gltf'
+ const url = '/car/parking_space_dae_V0.1.gltf'
应该是路径问题,可以在环境文件中配置一个基础路径如VITE_APP_BASE_URL(生产模式、开发模式都需要配置)
在页面中通过import.meta.env.VITE_APP_BASE_URL
使用这个变量,比如你的就可以写成import.meta.env.VITE_APP_BASE_URL + 'Cesium/model/...'