【发布时间】:2019-11-28 06:54:52
【问题描述】:
我正在尝试将图像文件从 public/images 文件夹中的父文件夹导入到组件 (Categories.vue),但图像未显示。
这是文件夹结构:
这是代码:
<template>
<div class="container">
<div class="row">
<div v-for="item in items" :key="item.name" class="col-lg-3 col-md-3">
<div class="img-container">
<img v-bind:src="item.src" alt="" class="img-fluid">
<p class="text-dark"> {{ item.subtitle }} </p>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
items: [
{
name:'first',
src:'./public/images/anubis.png',
subtitle: 'Anubis'
},
{
name:'second',
src:'public/images/sarcophagus.png',
subtitle: 'Sarcophagus'
},
{
name:'third',
src:'public/images/ra.png',
subtitle: 'Ra'
},
{
name:'fourth',
src:'public/images/eye-of-ra.png',
subtitle: 'Eyes of Ra'
}
]
}
}
}
</script>
我很确定我做的一切都是正确的。我尝试使用require(),但也失败了。我该如何解决这个问题?
【问题讨论】:
-
你可以在 stackoverflow 上轻松找到解决方案,只需花 5 分钟寻找它......stackoverflow.com/questions/54728285/…
-
你在使用 Vue CLI 吗?
-
@onuriltan 是的,我正在使用 vue cli