在vue引入的外部资源路径中以下project怎么去除:http://localhost/project/luban-motor-sdk/Assets/Textures/worldTerrain/layer.json
时间: 2023-08-21 17:06:11 浏览: 47
你可以使用相对路径来引入该资源,而不是使用绝对路径。如果该资源与你的Vue项目在同一目录下,则可以使用相对路径引用该资源。例如,如果你的Vue项目和该资源都在`/project`目录下,则可以使用以下相对路径引用该资源:
```
./luban-motor-sdk/Assets/Textures/worldTerrain/layer.json
```
这样,你就可以去除`http://localhost/project/`部分,只使用相对路径来引用该资源。
相关问题
在vue调用的资源路径中以下路径的project怎么去除:http://localhost/project/luban-motor-sdk/Assets/Textures/worldTerrain/layer.json
在Vue中,可以通过配置`vue.config.js`文件来设置webpack的publicPath属性,从而去除资源路径中的project。
1. 在项目根目录下创建`vue.config.js`文件
2. 在`vue.config.js`文件中添加如下代码:
```
module.exports = {
publicPath: './',
}
```
`publicPath`是webpack打包后的资源路径前缀,默认是`/`。将其设置为`'./'`即可去除路径中的project。
3. 如果还有其他资源路径需要去除project,可以在组件中使用`$route.path`获取当前路由路径,然后使用JavaScript的字符串操作方法去除`project`部分,例如:
```
<template>
<div>
<img :src="getImagePath('./Assets/Textures/worldTerrain/layer.json')" />
</div>
</template>
<script>
export default {
methods: {
getImagePath(path) {
const routePath = this.$route.path
const index = routePath.indexOf('project')
if (index !== -1) {
routePath = routePath.substring(0, index)
}
return `${routePath}${path}`
},
},
}
</script>
```
这样,就能够在Vue中去除资源路径中的project了。
vue3中请求http://localhost:9000/assets/images/tree.jpg出现错误
可能的问题原因有很多,以下是一些可能的解决方法:
1. 确认图片的路径是否正确,是否存在。
2. 确认是否有跨域问题,如果是跨域问题,可以在服务器端设置CORS(跨域资源共享)。
3. 确认是否有网络连接问题,可以在浏览器的开发者工具中查看网络请求的返回状态码和错误信息。
4. 确认是否有防火墙或代理软件阻止了网络请求,可以尝试关闭防火墙或代理软件后再试。
如果以上方法都无效,可以提供更详细的错误信息来帮助解决问题。