1

This is my data:

  data: () => ({
    html: [
      "../assets/html.png",
      "../assets/css.png",
      "../assets/scss.png",
      "../assets/materialize.png"
    ]
  })

I loop through like this, which shows the text stored in my data object:

<p v-for="img in html" :key="img">{{img}}</p>

However I can not use interpolation inside elements, so the following code does not work.

  <v-flex xs6 md3 v-for="img in html" :key="img">
    <img src={{img}} alt />
  </v-flex>

How can I do this?

Edit: No errors, but not working yet: The HTML link looks like this (working):

</v-flex>
  <v-flex xs6 md3><img src=../assets/html.png alt /></v-flex>
</v-layout>

src="/img/html.6ec9ec76.png"

Rendered by vue: src="../assets/materialize.png

Vue does not handle it correctly it seems!

2
  • To "interpolate" between the tags, you use {{ }} syntax, but to interpolate inside the opening tag, you've to use the v-bind directive, or the syntactic sugar with a colon only :. v-bind:src="img", or :src="img" instead of src={{img}} Commented Jan 12, 2020 at 11:50
  • This is a dublication, you can easly find answer in 1 min on stackoverflow Commented Jan 12, 2020 at 11:55

2 Answers 2

1

Try to use <img :src="img" alt /> instead

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

1 Comment

does not solve everything, no error, but nothing displayed. Updated my question
1

string interpolation can only be used to display for value in attribute you have to bind it:

<v-flex xs6 md3 v-for="img in html" :key="img">
    <img :src="img" alt />
</v-flex>

1 Comment

do i have to change the links in the data object? No error, but nothing gets displayed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.