image - 轮播单项组件中的图像 src。Vue + nuxt
问题描述
我必须在 singleItem 组件中显示产品 img。我有 API(文件),其中包含以下对象:
{
"name": "stand",
"type": "T01",
"link": "xx/xxx/317951/?cv=6&board=cat_all__type_all__id_4244",
"width": 148,
"height": 53,
"depth": 32,
"img": "assets/images/stand/317951.jpg",
"img_webp": "assets/images/stand/317951.webp",
"stand_type": "1"
},
在 singleItem 组件中,我尝试:
<div class="item">
<div class="item__img">
<img :src="item.img"> -- display nothing
<img :src="'~/' + item.img"> display nothing
<img src="~/assets/images/shelf/317951.jpg"> - show right img
</div>
{{item.img}} - display string 'assets/images/stand/317951.jpg'
请给我一些解决方案或提示来处理它。
解决方案
您必须require
按如下方式使用该指令:
<img :src="require('~/' + item.img)">
参见文档:https ://nuxtjs.org/docs/2.x/directory-structure/assets
另一种方法是将静态资产 (jpeg/webp) 移动到 nuxtstatic
目录中。
例如,对于保存在以下路径的图像文件static/images/stand/317951.jpg
,公共源将在以下 URL 可用/images/stand/317951.jpg
(或完整 url: http://localhost:3000/images/stand/317951.jpg
)
推荐阅读
- spring-boot - 如何使用 Spring Webflux 返回 GZIP 响应?
- excel - 合并 2 个工作表并多次复制工作表 1 的所有行
- facebook - 带有 Facebook 的 Azure Web App Bot Webhook 文本始终放在 V4 上
- google-api - 为什么 Google API for QR 码现在不起作用?
- linux - 如何使用 fdisk 命名分区?
- charts - 谷歌折线图水平滚动
- python - 如何在 Mac 终端中使用命令行参数运行 exe 文件?
- php - 如何在移动视图中添加“添加到主屏幕”作为弹出窗口
- c++ - DICOM 切片图像位置(患者)标签值的设置方法
- php - 以表格编号从数据库中提供数据