vue-单向数据流1

什么是单向数据流
数据从父组件流向子组件,只能单向绑定。在子组件内部不应该修改父组件传递过来的数据

改变props的情况
1.作为data中局部数据的初始值使用
2.作为子组件中的computed属性

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="./style.css">
<script src="./vue.js"></script>
</head>

<body>
<div id="app">
<custorm :count="count"></custorm>

</div>
<script>
Vue.component('custorm',{
data:function(){
return {
incriem:this.count //作为局部组件data的初始值
}
},
props:['count'],
template:`
<div>
<h2>我是自定义组件1</h2>
<button @click="creat">点击</button>
{{incriem}}
</div>
`,
methods:{
creat(){
this.incriem++;
}
}
})

let vm=new Vue({
el:"#app",
data:{
count:0
}

})
</script>
</body>
</html>