vue2复习
v-for语句
<!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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>
<body>
<div id="app">
<!-- in 后面可以跟普通数组、对象数组、对象、数字 -->
<!-- 使用v-for去迭代数字,从1开始,python当中从0开始 -->
<p v-for="count in 10">这是第{
{
count}}</p>
</div>
<script>
new Vue({
el:'#app',
data:{
}
})
</script>
</body>
</html>
遍历对象
<!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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>
<body>
<div id="app">
<!-- in 后面可以跟普通数组、对象数组、对象、数字 -->
<!-- 使用v-for去迭代数字,从1开始,python当中从0开始 -->
<!-- <p v-for="count in 10">这是第{
{
count}}次循环</p> -->
<p v-for='info in user'>{
{
info}}</p>
</div>
<script>
new Vue({
el:'#app',
data:{
user:{
id:1,
name:'holy',
gender:"男"
}
}
})
</script>
</body>
</html>
val,key形式
<!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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>
<body>
<div id="app">
<!-- in 后面可以跟普通数组、对象数组、对象、数字 -->
<!-- 使用v-for去迭代数字,从1开始,python当中从0开始 -->
<!-- <p v-for="count in 10">这是第{
{
count}}次循环</p> -->
<!-- 遍历对象 直接遍历值 -->
<p v-for='val,key in user'>值:{
{
val}},键是{
{
key}}</p>
</div>
<script>
new Vue({
el:'#app',
data:{
user:{
id:1,
name:'holy',
gender:"男"
}
}
})
</script>
</body>
</html>
添加索引
<!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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>
<body>
<div id="app">
<!-- in 后面可以跟普通数组、对象数组、对象、数字 -->
<!-- 使用v-for去迭代数字,从1开始,python当中从0开始 -->
<!-- <p v-for="count in 10">这是第{
{
count}}次循环</p> -->
<!-- 遍历对象 直接遍历值 如果获取值和键,是值和键-->
<p v-for='val,key,i in user'>值:{
{
val}},键是{
{
key}},索引是{
{
i}}</p>
</div>
<script>
new Vue({
el:'#app',
data:{
user:{
id:1,
name:'holy',
gender:"男"
}
}
})
</script>
</body>
</html>
遍历数组
案例
引入样式
选择样式复制
<!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>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<!