vue指令:v-for
注意:代码所需vue可以通过npm i vue --save下载,然后引入即可案例<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="vi
·
注意:代码所需vue可以通过npm i vue --save下载,然后引入即可
案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>v-for</title>
<script src="./node_modules/vue/dist/vue.js"></script>
<style>
.course {
overflow: hidden;
}
.every {
width: 200px;
height: 200px;
border: 1px solid blue;
float: left;
margin: 10px;
}
</style>
</head>
<body>
<div id="app">
<ul>
<li v-for="(item,index) in comments">{{item}}</li>
<li v-for="(item,index) in comments">{{index}}</li>
</ul>
<div class="course">
<div class="every" v-for="(item,index) in course">
<h3>名称:{{item.title}}</h3>
<div>价格
<span v-if="item.price!=0">{{item.price}}</span>
<span c-else>免费学习</span>
</div>
</div>
</div>
</div>
<script>
new Vue({
el: "#app",
data: {
//评论
comments: ['妲己', '貂蝉', '后羿'],
//课程
course: [{
id: 1,
title: "暑假班",
price: 200,
},
{
id: 2,
title: "数学特长班",
price: 199,
},
{
id: 3,
title: "疯狂物理",
price: 299,
},
{
id: 4,
title: "疯狂物理2",
price: 0
},
]
},
methods: {}
})
</script>
</body>
</html>
效果:
更多推荐
已为社区贡献4条内容
所有评论(0)