Search code examples
vuejs2directivevue-cli-3

VueCLI + Static Assets + Directive


I follow guide here: Vue CLI - include image from assets folder in static file

So in assets folder I have img\pic.jpg. I can call that image using normal html and css:

<img src="~@/assets/img/pic.jpg">

<style scoped>
.app {
  background: url(~@/assets/img/pic.jpg);
}
</style>

But for directive (correct me if the term if wrong), I tried this and of course failed. Can you help?

<img :src="'~@/assets/'+user.profilepic">

//Note:  user.profilepic = "img/pic.jpg"

Solution

  • could you try

    <img :src="require(`@/assets/${user.profilepic}`)" />