5

Clearly I'm missing something simple here. Inside a template I'm simply trying to add a path to an image file name sourced from an object. I've tried a bunch of things, back ticks mustaches, etc. but Vue doesn't like any of them. How do I format this properly?

<img class="img-fluid" v-bind:src="assets/img/" {{playerDetail.pic}} alt="">


playerDetail.pic = "player_image.png"
Bert
  • 80,741
  • 17
  • 199
  • 164
Loomernescent
  • 81
  • 2
  • 7

2 Answers2

3

Do it like this

img class="img-fluid" v-bind:src="'assets/img/' + playerDetail.pic" alt=""> 
Vamsi Krishna
  • 30,568
  • 8
  • 70
  • 78
  • Thanks @user7814783 this worked but I ran into issues with the webpack-simple template and the app not being able to find the images unless I copied them across to the dist/ folder so I ended up using a computed. – Loomernescent May 23 '17 at 09:05
1

Vue does not support using Mustache syntax on HTML attributes.Reference

img class="img-fluid" :src="'assets/img/' + playerDetail.pic" alt="">

or

you can use the ES6 Template literals

img class="img-fluid" :src="`assets/img/${playerDetail.pic}`" alt="">
tony19
  • 125,647
  • 18
  • 229
  • 307