如何在Vue JavaScript中引用静态资产 [英] How to reference static assets within vue javascript
本文介绍了如何在Vue JavaScript中引用静态资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找引用静态资产的正确网址,例如Vue javascript中的图像.
I'm looking for the right url to reference static assets, like images within Vue javascript.
例如,我正在使用自定义图标图像创建传单标记,并且尝试了多个URL,但是它们都返回404 (Not Found)
:
For example, I'm creating a leaflet marker using a custom icon image, and I've tried several urls, but they all return a 404 (Not Found)
:
Main.vue:
var icon = L.icon({
iconUrl: './assets/img.png',
iconSize: [25, 25],
iconAnchor: [12, 12]
});
我尝试将图像放到资产文件夹和静态文件夹中,但是没有运气.我是否必须告诉Vue以某种方式加载这些图像?
I've tried putting the images in the assets folder and the static folder with no luck. Do I have to tell vue to load those images somehow?
推荐答案
对于希望从模板中引用图像的任何人,您都可以使用'@'直接引用图像.
For anyone looking to refer images from template, You can refer images directly using '@'
示例:
<img src="@/assets/images/home.png"/>
这篇关于如何在Vue JavaScript中引用静态资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文