代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue.js常用指令的测试</title>
</head>
<body>
<div id="app">
<ul>
<li v-for="(item,index) in list" :key="index" v-if="index % 2 ==0">{{index}}--{{item}}</li>
</ul>
</div>
</body>
<script src="vue.min.js"></script>
<script>
var VM = new Vue({
el:'#app',
data:{
list:[1,2,3,4,5],
}
});
</script>
</html>
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue.js常用指令的测试</title>
</head>
<body>
<div id="app">
<ul>
<li v-for="(value,key) in user">{{key}}--{{value}}</li>
</ul>
</div>
</body>
<script src="vue.min.js"></script>
<script>
var VM = new Vue({
el:'#app',
data:{
user:{uname:'itcast',age:10},
}
});
</script>
</html>
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue.js常用指令的测试</title>
</head>
<body>
<div id="app">
<ul>
<li v-for="(item,index) in userlist" :key="item.user.uname">
<div v-if="item.user.uname == 'itheima'" style="background: #00f50c">
{{index}}--{{item.user.uname}}--{{item.user.age}}
</div>
<div v-else="">
{{index}}--{{item.user.uname}}--{{item.user.age}}
</div>
</li>
</ul>
</div>
</body>
<script src="vue.min.js"></script>
<script>
var VM = new Vue({
el:'#app',
data:{
userlist:[
{user:{uname:'itcast',age:10}},
{user:{uname:'itheima',age:11}}
]
}
});
</script>
</html>