Skip to content

Commit 65752ea

Browse files
committed
父组件向子组件传递数据
1 parent 37a7e28 commit 65752ea

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

vuejs入门基础/my-second-vue-project/src/App.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
{{item.label}}
88
</li>
99
</ul>
10+
<component-a msgfromfather='you die!'></component-a>
1011
</div>
1112
</template>
1213

1314
<script>
1415
import Store from './store'
16+
import ComponentA from './components/componentA'
1517
export default {
1618
data: function () {
1719
return {
1820
title: 'this is a todo list',
1921
items: Store.fetch(),
20-
newItem: '',
21-
liClass: 'thisisliClass'
22-
22+
newItem: ''
2323
};
2424
},
25+
components:{ComponentA},
2526
watch:{
2627
items:{
2728
handler:function(items){

vuejs入门基础/my-second-vue-project/src/components/Hello.vue renamed to vuejs入门基础/my-second-vue-project/src/components/componentA.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
<template>
22
<div class="hello">
33
<h1>{{ msg }}</h1>
4+
<h1>{{msgfromfather}}</h1>
5+
<button v-on:click="onClickMe">Click!</button>
46
</div>
57
</template>
68

79
<script>
810
export default {
911
data () {
1012
return {
11-
msg: 'Hello Vue!'
13+
msg: 'hello from component a!'
1214
}
15+
},
16+
props:['msgfromfather'],
17+
methods:{
18+
onClickMe:function(){
19+
console.log(this.msgfromfather);
20+
}
1321
}
1422
}
1523
</script>
@@ -20,3 +28,5 @@ h1 {
2028
color: #42b983;
2129
}
2230
</style>
31+
32+

0 commit comments

Comments
 (0)