None of the methods placing the image as a tag or a background image works. Even though the path is correct. Written with the official docs. I’ve also tried installing vue-loader and giving a img src path, but it did’n help either.
<template>
<a href="#" class="header__top-item facebook" :style="image"> </a>
<img alt="" src="../assets/icons/facebook-header.svg" />
<img v-bind:src="require('../assets/icons/facebook-header.svg')" />
</template>
<script>
data() {
return {
image: { backgroundImage: 'url(../assets/icons/facebook-header.svg)' },
};
}
</script>
2
Answers
In Vue.js, you can import and use images inside a component by using the require function or by importing the image directly.
Try this:
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?