I would like to suggest a feature which we could manage a first and a last pointer when looping through some object, as of below:
// Array
$authors = [ 'john', 'mike', 'taylor'];
When using this array in a regular field, which is not listed (<li></li>
), would be nice to have some thing like that, in order to identify when the loop starts and when it ends:
<template v-for="author in authors">
{{ author }}<span v-if="! loop.last">, </span><span v-if="! loop.last">.</span>
</template>
Which would result to:
john, mike, taylor.
Just the idea, not sure if would be better to have loop.first/last or even author._first/last.
Thanks!
Just create a method:
Vue.prototype.$last = function (item, list) {
return item === list[list.length - 1]
}
Then:
<span v-if="!$last(author, authors)">...</span>
Thanks!
Most helpful comment
Just create a method:
Then: