Vue —— v-for列表渲染
-
v-for
循环数组元素,整理内容显示到页面上
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>for.html</title>
<script src="../js/vue.js"></script>
<link type='text/css' rel='styleSheet' href='../css/style.css' >
</head>
<body>
<div id="example">
<ul>
<!-- 传回的第一个值为元素,第二个值为索引 -->
<li v-for="(game, index) in games">
{{index+1}}. {{game.title}} : {{game.price}}元
</li>
</ul>
</div>
</body>
<script>
new Vue({
el: "#example",
data: {
//list数组
games: [
{title: "魂斗罗2", price: 150},
{title: "超级玛丽", price: 420},
{title: "坦克大战", price: 60},
{title: "空中战机3", price: 700}
]
}
});
</script>
</html>

浙公网安备 33010602011771号