【发布时间】:2020-03-20 18:49:25
【问题描述】:
我开始使用 Vue CLI 构建一个应用程序,并且我在一个组件中有以下代码 sn-p:
<template>
<div v-loading="loading">
<el-carousel :interval="4000" type="card" height="350px">
<el-carousel-item v-for="element in persons" :key="element.id">
<div class="testimonial-persons">
<el-avatar :size="80">
<img :src="require('@assets/testimonial/'+ element.photo)">
</el-avatar>
<h3>{{element.name}}</h3>
<h4>{{element.occupation}}</h4>
<hr style="width:50%;">
<p>"{{element.comment}}"</p>
</div>
</el-carousel-item>
</el-carousel>
</div>
</template>
页面加载后,我请求一个 API,该 API 返回我存储在 persons 中的对象数组以迭代模板。
人员
[
{
"testimonial_id": "2",
"persons_id": "1",
"id": "1",
"name": "Tom lima",
"occupation": "CEO / Pugmania",
"comment": "Simply the best customer service and attention to detail.",
"photo": "20200320193143R7pChVea3IkmujRRmS.png"
},
]
一切正常,问题在于图片加载。
当我手动输入图像名称时,它可以工作。
<img src="@assets/testimonial/20200320193143R7pChVea3IkmujRRmS.png">
有人知道怎么解决吗?
【问题讨论】:
标签: javascript vue.js webpack vuejs2 vue-cli