vue series of articles (9) v-for conditional loop

Based on the source data elements or molding render multiple blocks. The value of this directive, you must use a specific syntax alias in expression, provide an alias for the current traversing elements:

<div v-for="item in items"> {{ item.text }} </div>

example:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Vue.js</title>
	<script src="https://cdn.jsdelivr.net/npm/vue"></script>
	<link rel="stylesheet" type="text/css" href="style.css">
	
</head>
<body>
	<div id="app">
		<h1>v-for循环</h1>

		<!--数组下表-->
		{{ characters[0] }},
		{{ characters[1] }}
		<ul>
			<li v-for="(character,index) in characters">{{character}}</li>
		</ul>
		<ul>
			<li v-for="(user,index) in users">{{index+1}}-{{user.name}}-{{user.age}}</li>
		</ul>
		<div v-for="(user,index) in users">
			<h3>{{index}}.{{user.name}}.{{user.age}}</h3>
		</div>
		<template v-for="user in users">
			<div v-for="(val,key) in user">{{key}}-{{val}}</div>
		</template>
	</div>
	<script type="text/javascript" src="app.js"></script>
</body>
</html>

app.js

new Vue({
	el: '#app',
	data: {
		characters: ["Mario","luffy","yoshi"],
		users: [
			{name: 'Mario', age: 30},
			{name: 'luffy', age: 29},
			{name: 'yoshi', age: 30}
		]
	},
	methods: {
		
	},
	computed: {
		
	}
});

 

Guess you like

Origin blog.csdn.net/jsqfengbao/article/details/94740429