v-for is for loop
- If the traversed object is an array, the format of the expression is: (T, index) in List<T>, where T is the object type; if the target of the traversal is an object, the format of the expression is: (v,k,i) in T, where v is the value of the key, k is the key, i is the index, and T is the object
v-if means judgment
- When the expression is true, the content of the label is displayed, and when the expression is false, it is not displayed
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./[email protected]@vue/dist/vue.js"></script>
<div id="app">
<ul>
<li v-for="(people,index) in peopleArry">
index:{
{index}},name={
{people.name}},age={
{people.age}}<br>
对象键值对:
<span v-for="(v,k) in people">
{
{k}}={
{v}}
</span>
</li>
<li v-for="num in numArry">
<span v-if="num%2==0">
偶数:{
{num}}
</span>
<span v-if="num%2==1">
奇数:{
{num}}
</span>
</li>
</ul>
</div>
<script>
let app = new Vue({
el: '#app',
data: {
peopleArry: [{ name: 'a', age: 1 }, { name: 'b', age: 2 }, { name: 'c', age: 3 }],
numArry: [1, 2, 3, 4, 5, 6]
}
})
</script>
</body>
</html>