Home > Software engineering >  Adding vue.js to attribute src
Adding vue.js to attribute src

Time:04-29

I was trying to add the attribute src with vue.js to the img tag: <img v-bind:src="{object.url}"/> But for some reason the image is not loading.

CodePudding user response:

Vue's syntax is unlike React's where you use {object.url} a lot.
In Vue, this is like this directly

<img :src="object.url" />

CodePudding user response:

In a Vue template, a colon : prefixing an html attribute is a shorthand for v-bind. This allows you to use variables, computed etc. as attribute value instead of static values.

What you are trying is a react way which replace quotes around the attribute value with curly braces. But in Vue you can directly bind the variables without using curly braces.

Hence, It should be :

<img :src="object.url"/>
  • Related