v-for指令可以绑定数组的数据来渲染一个项目列表
v-for指令需要使用item in items形式的特殊语法,
items是源数据数组并且item是数组元素迭代的别名
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<span>{{message}}</span>
<hr>
<ul>
<li v-for="(item,index) in items">{{index+1}} {{item}}</li>
</ul>
<ul>
<li v-for="(value, key) in object">{{key}} {{value}}</li>
</ul>
<ul>
<li v-for="todo in todos">{{todo.title}}----{{todo.author}}</li>
</ul>
</div>
</body>
<script>
var vm = new Vue({
el: "#app",
data: {
message: "hello",
items: ["python", "go", "rust"],
object: {
title: "How to do lists in Vue",
author: "Jane Doe",
publisedAt: "2019-04-01",
},
todos: [
{
title: "Vue",
author: "Jane Doe",
publisedAt: "2019-04-01",
},
{
title: "Python",
author: "Guido",
publisedAt: "1990-04-01",
},
]
}
})
</script>
</html>