Search code examples
imagevue.jsvuex

How to set default image using vuex store?


I wanted to set default image for the user in vuex. Here is my vuex store

state:{
default_image: "../assets/images/users/1.jpg"
},
getters:{
 Image:state=>state.default_image,
}

Then the App.vue

<template>
<img src=this.image alt="alt" />
</template>

<script>
import {mapGetters} from 'vuex'
export default {
      ...mapGetters({
                image:'Image',
            }),
}

but it does not work, the template does not see the image, but if I put the path directly in src without using vuex everything works. Can't figure out what's the problem


Solution

  • Try with the required please:

    :src="`require(${image})`"