0

I am trying to dynamically pass an image url to my vue application but it seems not to be working so now i am wondering if its even possible to do so.. Yes, Please let me know if this is possible in Vue / Vuetify

<v-img
  class="white--text align-end"
  height="200px"
  src="{{ book.imageUrl }}"
>
1

4 Answers 4

0

yes it is possible, just there is an error on your syntax.

suppose to use :src= instead of just normal src

:src="book.imageUrl"

colon in front of the attribute allow framework to see it as working code.

non colon will result the "{{ book.imageUrl }}" as normal string only

Sign up to request clarification or add additional context in comments.

9 Comments

No, that does not work. I get an error
sorry got correction
@KarinaTurtle without the {{ }}
Did as well and nothing
@KarinaTurtle could you check if your book.imageUrl image source exist in your folder ?
|
0

Did you try this?

:src="book.imageUrl"

I think you can't use {{var}} to pass a variable to attribute of Vue component

2 Comments

No this gives me an error..
show me the error. I think you are having another issue, it's not about image component with dynamic link :)
0

You should use require() to your image urls, as suggested by KaelWD in this issue.

<v-img
  class="white--text align-end"
  height="200px"
  :src="require(`${book.imageUrl}`)"
/>

Comments

0

This is what I have used in a project

:src="require('../../assets/img/logos/' + vendor.vendor_identifier + '.png')" 

Webpack needs you to restrict the amount of possible files by giving it a part of the path as a literal string, at least - or the whole path, in the best case.

Relevant docs: https://webpack.js.org/guides/dependency-management/#require-with-expression

So the method everyone mentioned is basically correct but you just have add half the path inside the require('../../assets/img/logos/') . Also can you show what you are sending in {{book.imageUrl}} ?

First I would hard code the link/path sent in book.imageUrl and see if the error exists

2 Comments

its coming from an api
Can you console.log(book.imageUrl) to see what the link looks like?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.