-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.子组件更改父组件数据但是不同步.html
52 lines (52 loc) · 1.25 KB
/
2.子组件更改父组件数据但是不同步.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<parent>
</parent>
</div>
<template id="tmpl">
<div>
<div>parent</div>{{name}}
<child :n="name"></child>
</div>
</template>
<script src="vue2.0.js"></script>
<script>
//parent child
var vm = new Vue({
el: '#app',
components: {
parent: {
template:'#tmpl ',
data(){
return {name:'beijing'}
},
components:{
child: {
template: '<div @click="update">child {{a}}</div>',
data(){
return {a:''}
},
mounted:function () {
this.a=this.n
},
methods:{
//在vue2.0中。子组件是不能更改父组件数据的
update(){
this.a='lm'
}
},
props:{n:String}
}
}
}
}
})
</script>
</body>
</html>