0

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"
Coisox
  • 1,002
  • 1
  • 10
  • 22

1 Answers1

1

could you try

<img :src="require(`@/assets/${user.profilepic}`)" />
Adem yalçın
  • 176
  • 1
  • 6
  • Why should the OP try it? Please, consider adding a dedscription of the proposed solution. – il_raffa Apr 19 '19 at 11:12
  • Thank you its working! Sadly I didn't quite understand. I have seen this kind of codes but confuse when to use. Will takes some times to get familiar – Coisox Apr 19 '19 at 12:21