[Vuejs]-Vue two array loop in one ul

0👍

You can make computed property:

computed: {
   something: function () {
      return this.fragM.concat(this.fragP);
    }
}

And use it in template:

<ul v-for="frag in something"...

0👍

If the two arrays will always be the same size (or one will reliably be smaller), use indexes. For example:

<ul v-for="(frag, index) in fragM" :key="index"> 
// (keep in mind that this creates a ul for every set of 2, probably not desired)
    <li>{{ fragM[index] }}</li>
    <li>{{ fragP[index] }}</li>
</ul>

Once you get that working nicely, convert it to a method that sanity checks your array size and avoids undefined results.

Leave a comment