如何在 vue javascript 中引用静态资产 [英] How to reference static assets within vue javascript
本文介绍了如何在 vue javascript 中引用静态资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找正确的 url 来引用静态资产,例如 Vue javascript 中的图像.
I'm looking for the right url to reference static assets, like images within Vue javascript.
例如,我正在使用自定义图标图像创建传单标记,并且我尝试了多个网址,但它们都返回 404(未找到)
:
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屋!
查看全文