我认为这应该很简单,但是我在如何在 Vue 单文件组件中导入和使用图像时遇到了一些麻烦。有人可以帮我怎么做吗?这是我的代码片段:
<template lang="html">
<img src="zapierLogo" />
</template>
<script>
import zapierLogo from 'images/zapier_logo.svg'
export default {
}
</script>
<style lang="css">
</style>
我曾尝试使用 :src
, src="{{ zapierLogo }}"
等。但似乎没有任何效果。我也找不到任何例子。有什么帮助吗?
原文由 aks 发布,翻译遵循 CC BY-SA 4.0 许可协议
很简单:
取自 vue cli 生成的项目。
如果您想将图像用作模块,请不要忘记将数据绑定到您的 Vuejs 组件:
还有一个较短的版本: