==================================================$children
this.$children[0]. name //获取子组件data
this.$children[0].showMessage() //获取子组件方法
$children的缺点:子组件顺序改变下标会改变原来的代码可能不适用(多子组件情况下)
父组件:
<div id="app">
<cpn></cpn>
<cpn></cpn>
<cpn></cpn>
<button @click="btnClick">获取子组件的对象</button>
</div>
<script>
const app=new Vue({
el:"#app",
components:{cpn},
methods:{
btnClick(){
//方式一、$children(子组件顺序改变时不适用)
for(le