Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use v-for instruction in Vue.js

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the v-for instruction in Vue.js. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

What is the v-for instruction

In Vue.js, we can use the v-for instruction to repeatedly render elements based on the source data. In other words, you can use v-for instructions to achieve traversal functions, including traversing arrays, objects, array objects, and so on.

2. Ergodic array

The code example is as follows:

Document _ window.onload=function () {/ / build vue instance new Vue ({el: "# my", / / el is element, indicating the mounted element Cannot be mounted on HTML and body elements data: {array: [1mem2mem3re4], / / Array} / / method methods: {}}) below use v-for to traverse the array to show only the value {{v}} display value and index value: {{v}} Corresponding index: {{index}}

Where index represents the index of the array

The effect is shown in the following figure:

Note: the use of $index to get array indexes has been removed from the latest version

Third, traversing objects

The code example is as follows:

Document _ window.onload=function () {/ / build vue instance new Vue ({el: "# my", / / el is element, indicating the mounted element Cannot be mounted on HTML and body elements data: {array: [1mem2mem3re4], / / Array} / / method methods: {}}) below use v-for to traverse the array to show only the value {{v}} display value and index value: {{v}} Corresponding index: {{index}}

The effect is shown in the following figure:

Traversing array objects

The code example is as follows:

Use the v-for instruction to traverse the array object _ window.onload=function () {/ / build the vue instance new Vue ({el: "# my", / / el is element, which represents the mounted element Cannot mount on HTML and body elements data: {lists: [{name: "kevin", age:23}, {name: "tom", age:25}, {name: "喜悦", age:28}]} / / method methods: {}}) the following use v-for to traverse array objects to show only values Name value: {{list.name}} Age value: {{list.age}} display value and key name value: {{list.name}}, age value: {{list.age}}, corresponding key: {{index}}

The effect is shown in the following figure:

Thank you for reading! This is the end of this article on "how to use v-for instructions in Vue.js". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report