Laravel Vue - 如何让 vue 在公共文件夹中查找图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50650143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Vue - How to make vue to look for images in public folder
提问by Deepak Tiwari
I am trying to load images from the public folder in the vue components. The asset helper doesn't work in vue , so I need to use the format
我正在尝试从 vue 组件中的公共文件夹加载图像。资产助手在 vue 中不起作用,所以我需要使用格式
<img :src="'img/ic_add-sm.svg'" >
But instead of looking for the images in the public folder , vue is appending the current URL to the image path. For example , if the url is www.example.com/posts
但是,vue 不是在 public 文件夹中查找图像,而是将当前 URL 附加到图像路径。例如,如果 url 是 www.example.com/posts
it adds www.example.com/posts/img/ic_add-sm.svg instead of www.example.com/img/ic_add-sm.svg
它添加了 www.example.com/posts/img/ic_add-sm.svg 而不是 www.example.com/img/ic_add-sm.svg
回答by Mikew305
Add a forward slash to the beginning of your image path.
在图像路径的开头添加一个正斜杠。
<img :src="'/img/ic_add-sm.svg'">
Since you don't appear to be doing anything special you should be able to just use
由于您似乎没有做任何特别的事情,因此您应该可以使用
<img src="/img/ic_add-sm.svg">