在使用脚手架搭建vue环境的时候,需要将项目图片展示出来。项目图片为:
当使用如下语句时,启动项目后出现报错:
<p><img src="../assets/2.JPG"></p>
报错信息如下:
ERROR in ./src/assets/2.JPG 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
网上找了很多解决办法,大都还停留在vue2的时代,总之没有找到合适的解决办法。
---------------------------------------------------------------------------------------------------------------------------------
这里再插一句,如果将src写为:
<p><img src="./assets/2.JPG"></p>
会报这样的错误:
Module not found: Error: Can't resolve './assets/2.JPG' in 'C:\xxx\xxx\xxx\文件名\项目名\src\views'
这时因为
“./”:表示当前所在的目录;
“../”:表示当前目录的上一级目录;
“/”:表示根目录。
---------------------------------------------------------------------------------------------------------------------------------
后来试着把图片格式改为:
将src属性作同样修改:
<p><img src="../assets/2.jpg"></p>
竟然可以正常显示图片了。。。
有点迷。。。
如果有知道的朋友,还望不吝赐教。感谢!