vue初体验
u4250 2020-11-18
vue中使用列表与绑定按钮事件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li v-for='item in movies'>{{item}}</li>
</ul>
<h2>当前计数{{count}}</h2>
<button v-on:click="add">+</button>
<button v-on:click="count--">-</button>
</div>
<script type="text/javascript">
var app=new Vue({
el:"#app",
data:{
message:"hello vue",
movies:['海贼王','大话西游','肖申克的救赎','盗梦空间'],
count:0
},
methods:{
add:function(){
this.count++
},
}
})
</script>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 一.vue中的MVVM模式
# 二.创建vue实例传入的options
- [x] el:
- 类型:
string
|HTMLELement
- 作用:决定vue实例管理哪个DOM
- 类型:
- [x] data:
- 类型:
Object
|Function
(组件当中必须是函数) - 作用:vue实例对应的数据对象
- 类型:
- [x] methods:
- 类型:
{[key:string];Function}
- 作用:定义vue方法
- 类型:
- [ ] others:
# 三.vue的生命周期
待补充。。。。