我有一个带有ref属性的v-for
<Car v-for="(car, index) in allCars" :key="car['id']" ref="allCars"
@save="save(car['id'])" @remove="remove(car['id'])" />
<b-btn @click="addCar">Add Car</b-btn>
在我的addCar方法中,我想获取最新添加的汽车Vue组件
addCAr() {
this.allCars.push({id: null, name: null, color: null})
console.log(this.$refs.allCars) // at this point it only has the initall components, without the latest addition.
Vue.nextTick(() => {
console.log(this.$refs.allCars) // here it has an empty array
}
如何引用已添加的最新vue组件?