inleft
2022-08-26 fa1bd95d533444d7360d1ada127b7a3279a3901f
commit | author | age
bf6fbe 1 // 父组件中
L 2 <template>
3     <div class="hello_world">
4         <div>{{msg}}</div>
5         <com-a></com-a>
6         <button @click="changeA">点击改变子组件值</button>
7     </div>
8 </template>
9
10 <script>
11     import ComA from './article.vue'
12     export default {
13         name: 'HelloWorld',
14         components: {
15             ComA
16         },
17         data() {
18             return {
19                 msg: 'Welcome'
20             }
21         },
22
23         methods: {
24             changeA() {
25                 // 获取到子组件A
26                 this.$children[0].messageA = 'this is new value'
27             }
28         }
29     }
30 </script>