This article will take you through Vue’s list rendering command: v-for. I hope it will be helpful to you!

Vue’s list rendering
##1.1.v-for
⭐⭐ Personally, I feel that it is actually a for loop with basic syntax. The usage is similar, but the form is different. If you understand it, you will be able to use it. (Learning video sharing:
vue video tutorial)
v-for="item in 数组"
v-for="(item, index) in 数组"Example of traversing an array:
<div class="item" v-for="item in products">
<h3 id="商品-item-name">商品:{{item.name}}</h3>
<span>价格:{{item.price}}</span>
<p>秒杀:{{item.desc}}</p>
</div>
const app = Vue.createApp({
data() {
return {
//2.数组 存放的是对象
products: [
{ id: 11, name: "mac", price: 1000, desc: "99" },
],
};
},
});
app.mount("#app");2. Traversing objects ⭐⭐
v-for also supports traversing objects, and supports one, two or three parameters:
- One parameter: "value in object ";
- Two parameters: "(value, key) in object";
- Three parameters: "(value, key, index) in object";
Each item is a number;
<!-- 2.遍历对象 -->
<ul>
<li v-for="(value,key,index) in info">
{{value}} - {{key}} - {{index}}
</li>
</ul>
const app = Vue.createApp({
data() {
return {
info: { bame: "why", age: 18, height: 1.88 },
};
},
});
app.mount("#app");3. Traversing strings<li v-for="item in 100">{{item}}</li>
1.2 .v-for and template
⭐⭐ We can use the template element to loop through rendering a piece of content containing multiple elements
Why not here What about using div?
I didn’t think much about this when I was studying before. I discovered this problem when I was sorting out my notesReason:
- If it is wrapped by div, the div will also be rendered.
- But if it is wrapped by template, the template will not be rendered. Compared with using div, it will save the use of an unnecessary div tag.
In fact, the function of template is a template placeholder, which can help us wrap elements. During the loop process, template will not be rendered to the page.
- div (if div has no actual meaning, you can use template to replace it)
<div>
<span>{{value}}</span>
<strong>{{key}}</strong>
<i>{{index}}</i>
</div>
- template
<template v-for="(value,key,index) in infos">
<span>{{value}}</span>
<strong>{{key}}</strong>
<i>{{index}}</i>
</template>
1.3.v-for array update detection##⭐⭐
Vue wraps the change methods of the listened array, so they will also trigger view updates:
push() Insert an element from the back of the array- pop() Delete an element from the back of the array
- shift() Delete an element from the front of the array
- unshift() Insert an element from the front of the array
- splice() Cut, insert, and delete the array
- sort() Sort
- reverse() Reverse
- The usage of these methods is actually similar in js. When you think of it, look it up again
The above method will directly modify the original array;
- However, some methods will not replace the original array, but will generate a new array, such as filter(), concat() and slice();
//并不是完整写法!!! <li v-for="item in names">{{item}}</li> names: ["abc", "bac", "aaa", "cbb"], // 1.直接将数组修改为一个新的数组 this.names = ["cc", "kk"]; // 2.通过一些数组的方法,修改数组中的元素 this.names.push("cc"); this.names.pop(); this.names.splice(2, 1, "cc"); this.names.sort(); this.names.reverse();[Recommended related video tutorials:
The above is the detailed content of A brief analysis of Vue's list rendering instructions: v-for. For more information, please follow other related articles on the PHP Chinese website!
The Frontend Landscape: How Netflix Approached its ChoicesApr 15, 2025 am 12:13 AMNetflix's choice in front-end technology mainly focuses on three aspects: performance optimization, scalability and user experience. 1. Performance optimization: Netflix chose React as the main framework and developed tools such as SpeedCurve and Boomerang to monitor and optimize the user experience. 2. Scalability: They adopt a micro front-end architecture, splitting applications into independent modules, improving development efficiency and system scalability. 3. User experience: Netflix uses the Material-UI component library to continuously optimize the interface through A/B testing and user feedback to ensure consistency and aesthetics.
React vs. Vue: Which Framework Does Netflix Use?Apr 14, 2025 am 12:19 AMNetflixusesacustomframeworkcalled"Gibbon"builtonReact,notReactorVuedirectly.1)TeamExperience:Choosebasedonfamiliarity.2)ProjectComplexity:Vueforsimplerprojects,Reactforcomplexones.3)CustomizationNeeds:Reactoffersmoreflexibility.4)Ecosystema
The Choice of Frameworks: What Drives Netflix's Decisions?Apr 13, 2025 am 12:05 AMNetflix mainly considers performance, scalability, development efficiency, ecosystem, technical debt and maintenance costs in framework selection. 1. Performance and scalability: Java and SpringBoot are selected to efficiently process massive data and high concurrent requests. 2. Development efficiency and ecosystem: Use React to improve front-end development efficiency and utilize its rich ecosystem. 3. Technical debt and maintenance costs: Choose Node.js to build microservices to reduce maintenance costs and technical debt.
React, Vue, and the Future of Netflix's FrontendApr 12, 2025 am 12:12 AMNetflix mainly uses React as the front-end framework, supplemented by Vue for specific functions. 1) React's componentization and virtual DOM improve the performance and development efficiency of Netflix applications. 2) Vue is used in Netflix's internal tools and small projects, and its flexibility and ease of use are key.
Vue.js in the Frontend: Real-World Applications and ExamplesApr 11, 2025 am 12:12 AMVue.js is a progressive JavaScript framework suitable for building complex user interfaces. 1) Its core concepts include responsive data, componentization and virtual DOM. 2) In practical applications, it can be demonstrated by building Todo applications and integrating VueRouter. 3) When debugging, it is recommended to use VueDevtools and console.log. 4) Performance optimization can be achieved through v-if/v-show, list rendering optimization, asynchronous loading of components, etc.
Vue.js and React: Understanding the Key DifferencesApr 10, 2025 am 09:26 AMVue.js is suitable for small to medium-sized projects, while React is more suitable for large and complex applications. 1. Vue.js' responsive system automatically updates the DOM through dependency tracking, making it easy to manage data changes. 2.React adopts a one-way data flow, and data flows from the parent component to the child component, providing a clear data flow and an easy-to-debug structure.
Vue.js vs. React: Project-Specific ConsiderationsApr 09, 2025 am 12:01 AMVue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.
How to jump a tag to vueApr 08, 2025 am 09:24 AMThe methods to implement the jump of a tag in Vue include: using the a tag in the HTML template to specify the href attribute. Use the router-link component of Vue routing. Use this.$router.push() method in JavaScript. Parameters can be passed through the query parameter and routes are configured in the router options for dynamic jumps.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.







