文章结构
$children的顺序不能保证,常规情况下,是按照组件的书写顺序来决定的,但是当有
异步组件的时候,顺序就不清楚了。
因此这种组件通信方式是不推荐的。
// 子组件
data() {
return {
a: 1
}
},
methods: {
clg(name){
console.log("hai! I'm",name);
}
},
// 父组件
mounted() {
console.log(this.$children[0]);
this.$children[0].clg('zhangsan');
console.log(this.$children[0].a);
},