javascript - 我如何从另一个文件 vue 添加图像
问题描述
我有图片
<div class="header-title">
<img
v-if="icon.length"
:src="icon"
class="header-icon"
>
{{ title }}
</div>
props: {
icon: {
type: String,
default: ''
}
}
我将此图像添加到另一个文件中:
<app-dropdown-card
title="Filters"
icon="@/assets/images/talent-pool/filter.svg"
/>
但我没有任何结果。图片就在那里 ( @/assets/images/talent-pool/filter.svg
) 浏览器看到标签img
,但看不到图片。
解决方案
// 假设您使用的是 Vue CLI 和单文件组件:
您必须import
在使用它的组件中提供图像,以及v-bind
图像源属性。
在您的情况下,它位于包含以下内容的文件中<app-dropdown-card ... />
:
<template>
<!-- ... -->
<app-dropdown-card
title="Filters"
:icon="filterImage"
/> <!-- Note the binding: ':icon' or 'v-bind:icon' -->
<!-- ... -->
</template>
<script>
// Note: Vue-CLI configures Webpack loaders for SVG files and other static assets:
import filterImage from "@/assets/images/talent-pool/filter.svg";
// ...
export default {
// ...
data() {
return {
filterImage // Note that you can't access globals from template directly
};
}
// ...
}
</script>
推荐阅读
- c# - 高效获取 IReadOnlyDictionary
从字典 - regex - 在正则表达式捕获组中,排除一个单词
- android - 如何使用android中的mpchart库在图表外设置矩形框?
- java - Android:写入外部存储的文件未显示
- linux - 当两个参数相似5分钟时,如何制作执行命令的脚本?
- android - 如何检测recyclerview在其边界之外的滚动?
- php - Laravel 显示带有项目、属性和产品的订单
- rounding - jq:错误:round/0 未定义在
- elasticsearch - 用于处理日志数据的 Elasticsearch 查询
- spring - 做mockMvc测试时使用Mockito注册spring bean