uniapp:二级目录部署H5静态图片资源请求路径不对

问题描述

引入方式

<image src="/static/user.png"></image>

由于url使用的是二级目录,http://www.demo.com/mini/

开发环境中没有问题,资源可以正常请求到

上线后,发现静态资源请求的路径是

http://www.demo.com/static/user.png

请求不到资源,返回了404

解决方式

网上给出了很多方式

<image src="../../static/user.png"></image>

<image src="@/static/user.png"></image>

都不能获取

<image :src="userImage"></image>

<script>
const userImage = require("../../static/user.png)
</script>

其实最后解决的方式也很简单,使用相对当前目录的方式

<image src="static/user.png"></image>

也就是把最前面的路径/ 去掉,上线后就获取正确的路径了

http://www.demo.com/mini/static/user.png

猜你喜欢

转载自blog.csdn.net/mouday/article/details/131620207