Vue项目:Failed to load resource: the server responded with a status of 404 (Not Found)

一、问题描述

在写Vue的前端项目时,调试发现无法取得资源文件的问题。
代码:
Vue项目:Failed to load resource: the server responded with a status of 404 (Not Found)_第1张图片
资源文件位置:
Vue项目:Failed to load resource: the server responded with a status of 404 (Not Found)_第2张图片
报错:
在这里插入图片描述

二、解决办法

将 ‘…/public/1.glb’ 改成 ‘/1.glb’ 即可。
Vue项目:Failed to load resource: the server responded with a status of 404 (Not Found)_第3张图片
Vue项目:Failed to load resource: the server responded with a status of 404 (Not Found)_第4张图片

三、原因总结

Vue项目指定项目的公共路径 (publicPath) 为根路径,如果访问 public 中的资源,Vue项目会从根路径 (/) 开始搜索,根路径默认是从 public 文件夹开始的。

你可能感兴趣的:(#,Vue,vue.js,前端,javascript)