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

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

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

会报错:vue

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的包,这里提供一个很是直接的办法:webpack

直接写 /static/img/xx.png

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

就能够了

缘由也很简单,mpvue已经通过打包在dist文件下已经生成了static文件,static文件下有img文件存放着打包出来的图片,就能够直接使用打包事后的图片啦!git

https://github.com/liangfengbo/frontendgithub

相关文章
相关标签/搜索