0

Now I am trying to get src from object to my vue.js component

export const Quizzes = [
  {
    firstWord: "happy",
    secondWord: "srećan",
    imageSrc: "../assets/happy--women.jpg",
  },
]

my data.js file looks like this

and how can i use this in my Vue.js component

<img class="happy-women" src="../assets/earth.jpg" alt="Quiz Image" />

here instead of src link

5
  • What's the vue version ? and what's the build tool vue cli or vite? Commented Aug 30, 2022 at 18:59
  • Can you try to use require function like this :src="require('../assets/earth.jpg')" Commented Aug 30, 2022 at 19:01
  • I am using Vite Commented Aug 30, 2022 at 19:10
  • Please share the whole code to make the picture clear Commented Aug 30, 2022 at 20:35
  • Not sure how Quizzes is added to your component but say you have it as an array in your component, you bind the <img> src like so: <img :src="Quizzes[i].imageSrc">. The index of the array can be from a v-for directive or some other logic inside your component Commented Aug 30, 2022 at 21:50

1 Answer 1

1

As per my understanding, You just simply want to bind the object imageSrc property value in the src attribute of img element in the template ? If Yes, Here you go :

<img v-for="(quiz, index) in Quizzes"
  :key="index"
  :class="`${quiz.firstWord}-${quiz.secondWord}`"
  :src="quiz.imageSrc"
  alt="Quiz Image" />
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.