Vue学习笔记(尚硅谷天禹老师)

Vue学习笔记

文章目录

1. Vue核心

1.1. Vue简介

1.1.1. 官网
1.1.2. 介绍与描述
  • 动态构建用户界面的渐进式JavaScript框架

  • 作者:尤雨溪

1.1.3. Vue的特点
  1. 遵循MVVM模式

  2. 编码简洁,体积小,运行效率高,适合移动/PC端开发

  3. 它本身只关注UI,可以引入其它第三方库开发项目

1.1.4.与其他JS框架的关联
  1. 借鉴 Angular 的模板数据绑定技术
  2. 借鉴 React 的组件化虚拟DOM技术
1.1.5. Vue周边库
  • vue-cli:vue脚手架
  • vue-resource
  • axios
  • vue-router:路由
  • vuex:状态管理
  • element-ui:基于vue的UI组件库(PC端)

1.2. 初识Vue

<!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>初识vue</title>
    <!-- 引入Vue -->
    <script src="../js/vue.js"></script>
</head>
<body>
    <!-- 准备好一个容器 -->
    <div id="root">
        <h1>Hello!{
  {name}}!</h1>
    </div>

    <script>
        Vue.config.productionTip = false // 阻止vue在启动时生成生产提示
        new Vue({
     
            el:'#root', //el用于指定当前Vue实例为哪个容器服务,值通常为css选择器字符串
            data:{
      //data用于存储数据,数据共el所指定的容器去使用
                name:'JOJO'
            }
        })
    </script>
</body>
</html>

效果:

注意:

  1. 想让Vue工作,就必须创建一个Vue实例,且要传入一个配置对象
  2. root容器里的代码依然符合html规范,只不过混入了一些特殊的Vue语法
  3. root容器里的代码被称为Vue模板
  4. Vue实例与容器是一一对应
  5. 真实开发中只有一个Vue实例,并且会配合着组件一起使用
  6. { {xxx}}中的xxx要写js表达式,且xxx可以自动读取到data中的所有属性
  7. 一旦data中的数据发生变化,那么模板中用到该数据的地方也会自动更新

1.3. 模板语法

<!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>vue模板语法</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h1>插值语法</h1>
        <h3>你好,{
  {name}}!</h3>
        <hr>
        <h1>指令语法</h1>
        <a v-bind:href="url">快去看新番!</a><br>
        <a :href="url">快去看新番!</a>
    </div>

    <script>
        Vue.config.productionTip = false 
        new Vue({
     
            el:'#root', 
            data:{
      
                name:'JOJO',
                url:'https://www.bilibili.com/'
            }
        })
    </script>
</body>
</html>

效果:

总结:

Vue模板语法包括两大类:

  1. 插值语法:

    • 功能:用于解析标签体内容
    • 写法:{ {xxx}},xxx是js表达式,且可以直接读取到data中的所有区域
  2. 指令语法:

    • 功能:用于解析标签(包括:标签属性、标签体内容、绑定事件…)
    • 举例:<a v-bind:href="xxx">或简写为<a :href="xxx">,xxx同样要写js表达式,且可以直接读取到data中的所有属性
    • 备注:Vue中有很多的指令,且形式都是v-???,此处我们只是拿v-bind举个例子

1.4. 数据绑定

<!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>数据绑定</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        单向数据绑定:<input type="text" v-bind:value="name"><br>
        双向数据绑定:<input type="text" v-model:value="name">
    </div>

    <script>
        Vue.config.productionTip = false 
        new Vue({
     
            el:'#root', 
            data:{
     
                name:'JOJO'
            }
        })
    </script>
</body>
</html>

效果:

总结:

  • Vue中有2种数据绑定的方式:

    1. 单向绑定(v-bind):数据只能从data流向页面
    2. 双向绑定(v-model):数据不仅能从data流向页面,还可以从页面流向data
  • 备注:

    1. 双向绑定一般都应用在表单类元素上(如:<input><select><textarea>等)
    2. v-model:value可以简写为v-model,因为v-model默认收集的就是value值

1.5. el与data的两种写法

<!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>el与data的两种写法</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h1>Hello,{
  {name}}!</h1>
    </div>

    <script>
        Vue.config.productionTip = false 
        //el的两种写法:
        // const vm = new Vue({
     
        //     // el:'#root', //第一种写法
        //     data:{
     
        //         name:'JOJO'
        //     }
        // })
        // vm.$mount('#root')//第二种写法

        //data的两种写法:
        new Vue({
     
            el:'#root', 
            //data的第一种写法:对象式
            // data:{
     
            //     name:'JOJO'
            // }
            //data的第二种写法:函数式
            data(){
     
                return{
     
                    name:'JOJO'
                }
            }
        })
    </script>
</body>
</html>

总结:

el有2种写法:

  1. 创建Vue实例对象的时候配置el属性
  2. 先创建Vue实例,随后再通过vm.$mount('#root')指定el的值

data有2种写法:

  1. 对象式
  2. 函数式
  • 如何选择:目前哪种写法都可以,以后学到组件时,data必须使用函数,否则会报错

由Vue管理的函数,一定不要写箭头函数,否则this就不再是Vue实例了

1.6. MVVM模型

  • MVVM模型:
    • M:模型(Model),data中的数据
    • V:视图(View),模板代码
    • VM:视图模型(ViewModel),Vue实例
<!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>mvvm</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>名称:{
  {name}}</h2>
        <h2>战队:{
  {rank}}</h2>
        <h2>测试:{
  {$options}}</h2>
    </div>

    <script>
        Vue.config.productionTip = false
        new Vue({
     
            el:'#root',
            data:{
      
                name:'uzi',
                rank:'RNG'
            }
        })
    </script>
</body>
</html>

效果:

总结:

  • data中所有的属性,最后都出现在了vm身上
  • vm身上所有的属性 及 Vue原型身上所有的属性,在Vue模板中都可以直接使用

1.7. Vue中的数据代理

总结:

  1. Vue中的数据代理通过vm对象来代理data对象中属性的操作(读/写)
  2. Vue中数据代理的好处:更加方便的操作data中的数据
  3. 基本原理:
    • 通过object.defineProperty()把data对象中所有属性添加到vm上。
    • 为每一个添加到vm上的属性,都指定一个getter/setter。
    • 在getter/setter内部去操作(读/写)data中对应的属性。

1.8. 事件处理

1.8.1. 事件的基本用法
<!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>事件的基本用法</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>hello,{
  {name}}</h2>
        <button v-on:click="showInfo1">点我提示信息1</button>
        <button @click="showInfo2($event,66)">点我提示信息2</button>
    </div>

    <script>
        Vue.config.productionTip = false 
        new Vue({
     
            el:'#root', 
            data:{
     
                name:'JOJO'
            },
            methods:{
     
                showInfo1(event){
     
                    console.log(event)
                },
                showInfo2(evnet,num){
     
                    console.log(event,num)
                }
            }
        })
    </script>
</body>
</html>

效果:

总结:

  1. 使用v-on:xxx@xxx绑定事件,其中xxx是事件名
  2. 事件的回调需要配置在methods对象中,最终会在vm上
  3. methods中配置的函数,==不要用箭头函数!==否则this就不是vm了
  4. methods中配置的函数,都是被Vue所管理的函数,this的指向是vm或组件实例对象
  5. @click="demo@click="demo($event)"效果一致,但后者可以传参
1.8.2. 事件修饰符
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>事件修饰符</title>
		<script type="text/javascript" src="../js/vue.js"></script>
		<style>
			*{
     
				margin-top: 20px;
			}
			.demo1{
     
				height: 50px;
				background-color: skyblue;
			}
			.box1{
     
				padding: 5px;
				background-color: skyblue;
			}
			.box2{
     
				padding: 5px;
				background-color: orange;
			}
			.list{
     
				width: 200px;
				height: 200px;
				background-color: peru;
				overflow: auto;
			}
			li{
     
				height: 100px;
			}
		</style>
	</head>
	<body>
		<div id="root">
			<h2>欢迎来到{
  {name}}学习</h2>
			<!-- 阻止默认事件 -->
			<a href="http://www.atguigu.com" @click.prevent="showInfo">点我提示信息</a>

			<!-- 阻止事件冒泡 -->
			<div class="demo1" @click="showInfo">
				<button @click.stop="showInfo">点我提示信息</button>
			</div>

			<!-- 事件只触发一次 -->
			<button @click.once="showInfo">点我提示信息</button>

			<!-- 使用事件的捕获模式 -->
			<div class="box1" @click.capture="showMsg(1)">
				div1
				<div class="box2" @click="showMsg(2)">
					div2
				</div>
			</div>

			<!-- 只有event.target是当前操作的元素时才触发事件 -->
			<div class="demo1" @click.self="showInfo">
				<button @click="showInfo">点我提示信息</button>
			</div>

			<!-- 事件的默认行为立即执行,无需等待事件回调执行完毕 -->
			<ul @wheel.passive="demo" class="list">
				<li>1</li>
				<li>2</li>
				<li>3</li>
				<li>4</li>
			</ul>

		</div>
	</body>

	<script type="text/javascript">
		Vue.config.productionTip = false

		new Vue({
     
			el:'#root',
			data:{
     
				name:'尚硅谷'
			},
			methods:{
     
				showInfo(e){
     
					alert('同学你好!')
				},
				showMsg(msg){
     
					console.log(msg)
				},
				demo(){
     
					for (let i = 0; i < 100000; i++) {
     
						console.log('#')
					}
					console.log('累坏了')
				}
			}
		})
	</script>
</html>

效果:

总结:

Vue中的事件修饰符:

  1. prevent:阻止默认事件(常用)
  2. stop:阻止事件冒泡(常用)
  3. once:事件只触发一次(常用)
  4. capture:使用事件的捕获模式
  5. self:只有event.target是当前操作的元素时才触发事件
  6. passive:事件的默认行为立即执行,无需等待事件回调执行完毕

修饰符可以连续写,比如可以这么用:@click.prevent.stop="showInfo"

1.8.3. 键盘事件
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>键盘事件</title>
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		<div id="root">
			<h2>欢迎来到{
  {name}}学习</h2>
			<input type="text" placeholder="按下回车提示输入" @keydown.enter="showInfo">
		</div>
	</body>

	<script type="text/javascript">
		Vue.config.productionTip = false

		new Vue({
     
			el:'#root',
			data:{
     
				name:'尚硅谷'
			},
			methods: {
     
				showInfo(e){
     
					console.log(e.target.value)
				}
			},
		})
	</script>
</html>

效果:

总结:

键盘上的每个按键都有自己的名称和编码,例如:Enter(13)。而Vue还对一些常用按键起了别名方便使用

Vue中常用的按键别名:

  • 回车:enter
  • 删除:delete (捕获“删除”和“退格”键)
  • 退出:esc
  • 空格:space
  • 换行:tab (特殊,必须配合keydown去使用)
  • 上:up
  • 下:down
  • 左:left
  • 右:right

注意:

  1. 系统修饰键(用法特殊):ctrl、alt、shift、meta

    • 配合keyup使用:按下修饰键的同时,再按下其他键,随后释放其他键,事件才被触发
    • 配合keydown使用:正常触发事件
  2. 可以使用keyCode去指定具体的按键,比如:@keydown.13="showInfo",但不推荐这样使用

  3. Vue.config.keyCodes.自定义键名 = 键码,可以自定义按键别名

1.9. 计算属性

<!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>计算属性</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        姓:<input type="text" v-model="firstName"><br><br>
        名:<input type="text" v-model="lastName"><br><br>
        姓名:<span>{
  {fullName}}</span>
    </div>

    <script>
        Vue.config.productionTip = false 

        new Vue({
     
            el:'#root', 
            data:{
      
                firstName:'张',
                lastName:'三'
            },
            computed:{
     
                fullName:{
     
                    get(){
     
                        return this.firstName + '-' + this.lastName
                    },
                    set(value){
     
						const arr = value.split('-')
						this.firstName = arr[0]
						this.lastName = arr[1]
                    }
                }
            }
        })
    </script>
</body>
</html>

效果:

总结:

  • 计算属性:

    • 定义:要用的属性不存在,需要通过已有属性计算得来。

    • 原理:底层借助了Objcet.defineproperty()方法提供的getter和setter。

    • get函数什么时候执行?

      1. 初次读取时会执行一次
      2. 当依赖的数据发生改变时会被再次调用
    • 优势:与methods实现相比,内部有缓存机制(复用),效率更高,调试方便

  • 备注:

    • 计算属性最终会出现在vm上,直接读取使用即可
    • 如果计算属性要被修改,那必须写set函数去响应修改,且set中要引起计算时依赖的数据发生改变
    • 如果计算属性确定不考虑修改,可以使用计算属性的简写形式
new Vue({
    el:'#root', 
    data:{ 
        firstName:'张',
        lastName:'三'
    },
    computed:{
    	fullName(){
		    return this.firstName + '-' + this.lastName
    	}
    }
})

1.10. 监视属性

1.10.1. 监视属性基本用法
<!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>监视属性</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>今天天气好{
  {info}}!</h2>
        <button @click="changeWeather">点击切换天气</button>
    </div>

    <script>
        Vue.config.productionTip = false 

        new Vue({
     
            el:'#root', 
            data:{
      
                isHot:true,
            },
            computed:{
     
                info(){
     
                    return this.isHot ? '炎热' : '凉爽' 
                }
            },
            methods:{
     
				changeWeather(){
     
					this.isHot = !this.isHot
				}
			},
            watch:{
     
                isHot:{
     
                    immediate:true, //初始化时让handler调用一下
                    //handler什么时候调用?当isHot发生改变时
                    handler(newValue,oldValue){
     
						console.log('isHot被修改了',newValue,oldValue)
					}
                }
            }
        })
    </script>
</body>
</html>

效果:

总结:

监视属性watch:

  1. 当被监视的属性变化时,回调函数自动调用,进行相关操作
  2. 监视的属性必须存在,才能进行监视
  3. 监视有两种写法:
    1. 创建Vue时传入watch配置
    2. 通过vm.$watch监视
vm.$watch('isHot',{
	immediate:true,
	handler(newValue,oldValue){
		console.log('isHot被修改了',newValue,oldValue)
	}
})
1.10.2. 深度监视
<!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>深度监视</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h3>a的值是:{
  {numbers.a}}</h3>
		<button @click="numbers.a++">点我让a+1</button>
		<h3>b的值是:{
  {numbers.b}}</h3>
		<button @click="numbers.b++">点我让b+1</button>
    </div>

    <script>
        Vue.config.productionTip = false 

        new Vue({
     
            el:'#root', 
            data:{
      
                isHot:true,
                numbers:{
     
                    a:1,
                    b:1,
                }
            },
            watch:{
     
                //监视多级结构中所有属性的变化
                numbers:{
     
                    deep:true,
					handler(){
     
						console.log('numbers改变了')
					}
                }
                //监视多级结构中某个属性的变化
				/* 'numbers.a':{
					handler(){
						console.log('a被改变了')
					}
				} */
            }
        })
    </script>
</body>
</html>

效果:

总结:

  • 深度监视:

    1. Vue中的watch默认不监测对象内部值的改变(一层)
    2. 在watch中配置deep:true可以监测对象内部值的改变(多层)
  • 备注:

    1. Vue自身可以监测对象内部值的改变,但Vue提供的watch默认不可以
    2. 使用watch时根据监视数据的具体结构,决定是否采用深度监视
1.10.3. 监视属性简写

如果监视属性除了handler没有其他配置项的话,可以进行简写。

<script type="text/javascript">
	Vue.config.productionTip = false //阻止 vue 在启动时生成生产提示。
		
    const vm = new Vue({
     
        el:'#root',
        data:{
     
            isHot:true,
        },
        computed:{
     
            info(){
     
                return this.isHot ? '炎热' : '凉爽'
            }
        },
        methods: {
     
            changeWeather(){
     
                this.isHot = !this.isHot
            }
        },
        watch:{
     
            //正常写法
            isHot:{
     
				handler(newValue,oldValue){
     
					console.log('isHot被修改了',newValue,oldValue)
				}
			}, 
            //简写
            isHot(newValue,oldValue){
     
				console.log('isHot被修改了',newValue,oldValue,this)
			}
        }
    })

    //正常写法
    vm.$watch('isHot',{
     
        handler(newValue,oldValue){
     
            console.log('isHot被修改了',newValue,oldValue)
        }
    })
    //简写
    vm.$watch('isHot',function(newValue,oldValue){
     
        console.log('isHot被修改了',newValue,oldValue,this)
    })
</script>
1.10.4. 监听属性 VS 计算属性

使用计算属性:

new Vue({
    el:'#root', 
    data:{ 
        firstName:'张',
        lastName:'三'
    },
    computed:{
    	fullName(){
		    return this.firstName + '-' + this.lastName
    	}
    }
})

使用监听属性:

new Vue({
	el:'#root',
	data:{
		firstName:'张',
		lastName:'三',
		fullName:'张-三'
	},
	watch:{
		firstName(val){
			setTimeout(()=>{
				this.fullName = val + '-' + this.lastName
			},1000);
		},
		lastName(val){
			this.fullName = this.firstName + '-' + val
		}
	}
})

总结:

  • computed和watch之间的区别:

    • computed能完成的功能,watch都可以完成
    • watch能完成的功能,computed不一定能完成,例如:watch可以进行异步操作
  • 两个重要的小原则:

    1. 所有被Vue管理的函数,最好写成普通函数,这样this的指向才是vm 或 组件实例对象
    2. 所有不被Vue所管理的函数(定时器的回调函数、ajax的回调函数等、Promise的回调函数),最好写成箭头函数,这样this的指向才是vm 或 组件实例对象。

1.11. 绑定样式

<style>
    .basic{
     
        width: 400px;
        height: 100px;
        border: 1px solid black;
    }
    .happy{
     
        border: 4px solid red;;
        background-color: rgba(255, 255, 0, 0.644);
        background: linear-gradient(30deg,yellow,pink,orange,yellow);
    }
    .sad{
     
        border: 4px dashed rgb(2, 197, 2);
        background-color: gray;
    }
    .normal{
     
        background-color: skyblue;
    }

    .atguigu1{
     
        background-color: yellowgreen;
    }
    .atguigu2{
     
        font-size: 30px;
        text-shadow:2px 2px 10px red;
    }
    .atguigu3{
     
        border-radius: 20px;
    }
</style>
<div id="root">
    <!-- 绑定class样式--字符串写法,适用于:样式的类名不确定,需要动态指定 -->
    <div class="basic" :class="mood" @click="changeMood">{
  {name}}</div> <br/><br/>

    <!-- 绑定class样式--数组写法,适用于:要绑定的样式个数不确定、名字也不确定 -->
    <div class="basic" :class="classArr">{
  {name}}</div> <br/><br/>

    <!-- 绑定class样式--对象写法,适用于:要绑定的样式个数确定、名字也确定,但要动态决定用不用 -->
    <div class="basic" :class="classObj">{
  {name}}</div> <br/><br/>

    <!-- 绑定style样式--对象写法 -->
    <div class="basic" :style="styleObj">{
  {name}}</div> <br/><br/>

    <!-- 绑定style样式--数组写法 -->
    <div class="basic" :style="styleArr">{
  {name}}</div>
</div>
<script type="text/javascript">
	Vue.config.productionTip = false
		
    const vm = new Vue({
     
        el:'#root',
        data:{
     
            name:'尚硅谷',
            mood:'normal',
            classArr:['atguigu1','atguigu2','atguigu3'],
            classObj:{
     
                atguigu1:false,
                atguigu2:false,
            },
            styleObj:{
     
                fontSize: '40px',
                color:'red',
            },
            styleObj2:{
     
                backgroundColor:'orange'
            },
            styleArr:[
                {
     
                    fontSize: '40px',
                    color:'blue',
                },
                {
     
                    backgroundColor:'gray'
                }
            ]
        },
        methods: {
     
            changeMood(){
     
                const arr = ['happy','sad','normal']
                const index = Math.floor(Math.random()*3)
                this.mood = arr[index]
            }
        },
    })
</script>

效果:

image-20210717181454771

总结:

  1. class样式:

    • 写法:class="xxx",xxx可以是字符串、对象、数组

    • 字符串写法适用于:类名不确定,要动态获取

    • 对象写法适用于:要绑定多个样式,个数不确定,名字也不确定

    • 数组写法适用于:要绑定多个样式,个数确定,名字也确定,但不确定用不用

  2. style样式:

    • :style="{fontSize: xxx}"其中xxx是动态值
    • :style="[a,b]"其中a、b是样式对象

1.12. 条件渲染

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>条件渲染</title>
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		<div id="root">
			<h2>当前的n值是:{
  {n}}</h2>
			<button @click="n++">点我n+1</button>

			<h2 v-show="true">Hello,{
  {name}}!</h2>

			<div v-if="n === 1">Angular</div>
			<div v-else-if="n === 2">React</div>
			<div v-else>Vue</div>
		</div>
	</body>

	<script type="text/javascript">
		Vue.config.productionTip = false

		const vm = new Vue({
     
			el:'#root',
			data:{
     
				name:'jojo',
				n:0
			}
		})
	</script>
</html>

效果:

总结:

  1. v-if:

    • 写法:

      1. v-if="表达式"
      2. v-else-if="表达式"
      3. v-else
    • 适用于:切换频率较低的场景

    • 特点:不展示的DOM元素直接被移除

    • 注意:v-if可以和v-else-ifv-else一起使用,但要求结构不能被打断

  2. v-show:

    • 写法:v-show="表达式"
    • 适用于:切换频率较高的场景
    • 特点:不展示的DOM元素未被移除,仅仅是使用样式隐藏掉

使用v-if的时,元素可能无法获取到,而使用v-show一定可以获取到

1.13. 列表渲染

1.13.1. 基本列表
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>基本列表</title>
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		<div id="root">
			<h2>人员列表(遍历数组)</h2>
			<ul>
				<li v-for="(p,index) in persons" :key="index">
					{
  {p.name}}-{
  {p.age}}
				</li>
			</ul>

			<h2>汽车信息(遍历对象)</h2>
			<ul>
				<li v-for="(value,k) in car" 
评论 210
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦入_凡尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值