I think this should be simple, but I am facing some trouble on how to import and use an image in Vue single file component. Can someone help me how to do this? Here is my code snippet:
<template lang="html">
<img src="zapierLogo" />
</template>
<script>
import zapierLogo from 'images/zapier_logo.svg'
export default {
}
</script>
<style lang="css">
</style>
I have tried using :src
, src="{{ zapierLogo }}"
, etc but nothings seems to work. was not able to find any example too. Any help?
As simple as :
Taken from the project generated by vue cli.
If you want to use your image as a module, do not forget to bind data to your vuejs component
And a shorter version :
If you wish to load them by webpack you can simply use
:src='require('path/to/file')'
Make sure you use:
otherwise it won't execute the require statement as Javascript.