且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

拼接不适用于数组行vue js

更新时间:2023-12-03 11:22:22

我发现挑战在于,您需要像以前一样在 HOUR 中添加唯一的ID.我已经更新了以前的答案

I discovered that the challenge is that you need to add a unique id in HOUR, as you had earlier. I have updated my previous answer

 hour: [
            {
              id: 1,
              "item-1": 10,
            },
            {
              id: 2,
              "item-2": 11,
            },
            {
              id: 3,
              "item-3": 12,
            },
          ],

请注意,已将分配给从 hour 对象获得的唯一ID.

Take note that key is assigned to the unique id gotten from the hour object.

:key="time.id"

并且 deleteItems 带有 index 有一个参数

@click="deleteTime(index)"

      <div class="hours" v-for="(time, index) in hour" :key="time.id">
        <button @click="deleteTime(index)">
          Content {{time.id}}
        </button>
      </div>

然后您的方法开始

deleteTime(index) {
            this.hour.splice(index, 1);
          },