[Vuejs]-Vue Dynamic Form Fields with v-for

0đź‘Ť

Found the answer here: https://forum.vuejs.org/t/array-index-as-v-for-key-results-in-problems-when-removing-items-from-the-list/4982/10

Basically, create a unique id instead of using the index from the v-for. You can add this function to your root’s “methods” object and call it on :key= like uuid(object):

     uuid(e) {
        if (e.uid) return e.uid;

        const key = Math.random()
          .toString(16)
          .slice(2);

        this.$set(e, "uid", key);

        return e.uid;
      }

Leave a comment