我尝试使用从JSON数据命名的图像,这些图像位于我在Vue中的资源中: my JSON:
cards: [
{
title: 'my Title'
image: 'myimagename.png'
style: 'color: green'
},
title: 'another Title'
image: 'myotherimagename.png',
style: 'color: red'
}
]然后我尝试这样做:
<q-card :style="card.style" class="dashboard-card text-white q-mt-md" v-for="card in cards"
:key="card.id" style="height: 132px; width: 132px">
<q-card-section dense>
<q-img
:src="require('../assets/icons/' + card.image)"
basic
/>
<div class="dashboard-card-title"> {{ card.title }}</div>
</q-card-section>
</q-card>但我总是得到一个404,我如何使用我的资产文件夹中的图像?
Error: Cannot find module './myimagename.png'
at webpackContextResolve (eval at ./src/assets/icons sync recursive ^\.\/.*$ (0.js:218), <anonymous>:27:11)
at webpackContext (eval at ./src/assets/icons sync recursive ^\.\/.*$ (0.js:218), <anonymous>:22:11)发布于 2021-04-19 01:02:03
我必须使用public/images之类的公用文件夹,并使用
:src="'/images/' + card.image"现在所有的工作都和预期的一样。
https://stackoverflow.com/questions/67124240
复制相似问题