mpvue小程序 Failed to load local image resource /images/xx.png

mpvue开发小程序时候,要添加静态本地图片

<img src="../../images/bg.png" alt="">

会报错:

VM14878:2 Failed to load local image resource /images/bg.png 
the server responded with a status of 404 (HTTP/1.1 404 Not Found) 

原因有很多种,解决办法可以改webpack,或mpvue的包,这里提供一个非常直接的办法:

直接写 /static/img/xx.png

比如:
<img src="/static/img/bg.png" >

就可以了

原因也很简单,mpvue已经经过打包在dist文件下已经生成了static文件,static文件下有img文件存放着打包出来的图片,就可以直接使用打包过后的图片啦!

https://github.com/liangfengbo/frontend

猜你喜欢

转载自www.cnblogs.com/baimeishaoxia/p/12718809.html