A
A
Alianos2021-04-22 10:16:58
Vue.js
Alianos, 2021-04-22 10:16:58

How to use v-for as a mutable property loop?

hello i have

<div v-for="i of 10" :key="i" class="frame" >
    </div>

But I need to assign a special background-image to each div, depending on the iterator, for example, according to this pattern
backgroundImage =
`url(${require("../assets/images/slides/" + this.$assetsResolution + "/" + i + ".jpg")})`;

where i is an iterator and this.$assetsResolution is just a static variable (the same for all divs)
How to implement it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-04-22
@Alianos

Component pseudocode:

<div v-for="index of 10" :key="index" class="frame" :style="`background-image: url(${getImageUrl(index)})`" >
  {{ index }}
</div>

{
  methods: {
    getImageUrl(index) {
      return `/images/slides/${this.$assetsResolution}/${index}.jpg`;
    }
  }
}

In general, something like this. And no require will work.
PS Wrote from the phone, did not check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question