首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue和Vuetify中的动态内容中没有渲染图像源

Vue和Vuetify中的动态内容中没有渲染图像源
EN

Stack Overflow用户
提问于 2020-12-24 08:51:12
回答 1查看 166关注 0票数 0

我目前正在开发一个组件,该组件可以使用v-tabv-tab-itemsv-tab-item呈现具有各自超文本标记语言内容的选项卡。在v-tab-item调用中,我有以下引用:

代码语言:javascript
复制
<v-card flat>
  <v-card-text v-html="item.content"></v-card-text>
</v-card>

它通过content属性呈现在items对象的相应项中定义的内容,如下所示:

代码语言:javascript
复制
data() { return tabNavToolbar: tabNavToolbarImg,
  items: [
          {
            tab: 'About',
            content: '<h2 class="mt-8">About</h2><p class="pt-5">Tabs are a form of secondary in-page navigation, helping to group different types of content in a limited space.</p><p class="pt-5">Use tabs to split long content into manageable chunks to avoid overwhelming the user. By default the first tab is selected.</p><v-card><v-col class="ml-0 mt-3 pt-8 px-10 pb-10 imgBackground d-flex justify-center"><img src="../../../assets/tabnavigation/tabnavigation-toolbar.png" width="100%" height="100%" alt="display of tab navigation toolbar"/></v-col></v-card>'
          }
   ]
}

但是,图像并未呈现,事实上,即使我在标准img标记中直接引用图像URL,它也会正确呈现。

我尝试了导入图像并绑定相应变量的想法,如下所示:

import tabNavToolbarImg from '../../../assets/tabnavigation/tabnavigation-toolbar.png'

代码语言:javascript
复制
data() { return tabNavToolbar: tabNavToolbarImg,
  items: [
          {
            tab: 'About',
            content: '<h2 class="mt-8">About</h2><p class="pt-5">Tabs are a form of secondary in-page navigation, helping to group different types of content in a limited space.</p><p class="pt-5">Use tabs to split long content into manageable chunks to avoid overwhelming the user. By default the first tab is selected.</p><v-card><v-col class="ml-0 mt-3 pt-8 px-10 pb-10 imgBackground d-flex justify-center"><img :src="tabNavToolbar" width="100%" height="100%" alt="display of tab navigation toolbar"/></v-col></v-card>'
          }
   ]
}

但这似乎也不起作用……有没有什么原因导致图像不能用这两种方法渲染出来,有没有办法解决这个问题?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-24 09:01:48

您需要对字符串中的图像执行require操作,以便webpack知道将位置替换为图像的正确路径。

试试这个:<img src="' + require('../../../assets/tabnavigation/tabnavigation-toolbar.png') + '" width="100%" height="100%" alt="display of tab navigation toolbar"/> `

完整的content

代码语言:javascript
复制
content: '<h2 class="mt-8">About</h2><p class="pt-5">Tabs are a form of secondary in-page navigation, helping to group different types of content in a limited space.</p><p class="pt-5">Use tabs to split long content into manageable chunks to avoid overwhelming the user. By default the first tab is selected.</p><v-card><v-col class="ml-0 mt-3 pt-8 px-10 pb-10 imgBackground d-flex justify-center"><img src="' + require('../../../assets/tabnavigation/tabnavigation-toolbar.png') + '" width="100%" height="100%" alt="display of tab navigation toolbar"/></v-col></v-card>'
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65432700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档