javascript - Vuejs: Use v-for to display an array of images from assets - Stack Overflow

I have 100 images named 1.png to 100.png in my assets folder. I want to display them using v-for, but I

I have 100 images named 1.png to 100.png in my assets folder. I want to display them using v-for, but I don't wanna hard code every url for them.

<div v-for="n in 100">
    <img src="../assets/photos/(1.png, 2.png...).png">
</div>

What should I do for the (1.png, 2.png...)? Should I use put them into data?

I have 100 images named 1.png to 100.png in my assets folder. I want to display them using v-for, but I don't wanna hard code every url for them.

<div v-for="n in 100">
    <img src="../assets/photos/(1.png, 2.png...).png">
</div>

What should I do for the (1.png, 2.png...)? Should I use put them into data?

Share Improve this question edited Sep 28, 2018 at 23:05 mruanova 7,1256 gold badges40 silver badges58 bronze badges asked Sep 28, 2018 at 18:50 JackJackJackJack 6323 gold badges12 silver badges29 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Use template literals to construct the src dynamically and then use v-bind:src to bind the src attribute:

<div v-for="n in 100">
    <img v-bind:src="`../assets/photos/${n}.png`">
</div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744146313a4560440.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信