需求如图:
代码如下:
//template
<component v-for="(plan,i) in item.plan" :ref="'son_'+index+'_'+i" :is="plan.type" :key="i" :pid="index" :id="i" @delete="onPlanDelete"></component>
//data
//tour值
tour:[
{
day: 1,
title: '',
date: '',
plan:[]
}
],
//添加项目的按钮参数,根据type的值,对应相应的component
Options: [
{
type: 'plane',
name: '机票',
},
{
type: 'sight',
name: '景点',
}, {
type: 'hotel',
name: '酒店',
},
......更多
]
vue调试工具下,如图:
尝试如下方法去获取子组件,但是不行,求助大家了
getContent(){
for(var i=0;i<this.tour.length;i++){
for(var sub=0;sub<this.tour[i].plan.length;sub++){
var zujian="son_"+i+"_"+sub+"[0]"
console.log(this.$refs.zujian)
}
}
}