最近在使用Vue模仿网易云音乐的App。
遇到了一个关于img的src属性动态绑定,图片不显示的问题。
我会在这里结合具体实例跟大家说一下原因和解决方法。
首先我们需要做的效果是点击播放按钮,切换成暂停按钮,再次点击,又切换成播放按钮。





我们可以发现在控制台报出了图片找不到的错误。
为什么为出现这个问题呢,我们发现在Vue项目运行的时候只有static文件夹,所以我们放在assets中的图片是加载不出来的。所以为了使图片显示出来,在动态绑定图片的时候我们需要把图片放在static文件夹



这样我们在运行代码的时候就可以发现图片已经加载出来了

网友评论