0

我在 v-for 中有一个组件

  <div
      v-for="(plan, index) in plans"
      :key="index"
    >

    <plan 
         :name="plan.name"
         :cost="plan.cost"
         :index="index"
        ref="myPlan"
       />
</div>

在该组件中,我有一个清除所有数据的方法。

  clear() {
      this.cost = '';
      // some more clearing code
    },

我正在尝试通过调用此方法来清除计划。

  this.$refs.myPlan.clear();

这不起作用,因为 ref 是一个数组,但这确实清除了第一个计划

   this.$refs.myPlan[0].clear();

如何在所有计划上调用 clear 方法?

4

0 回答 0