K
K
Ksey1232019-05-14 08:09:20
Vue.js
Ksey123, 2019-05-14 08:09:20

How to remove elements following the selected element?

I make breadcrumbs, when moving, say, to the middle of the chain, it is necessary that the elements in front are removed from the array, only the active element and what was in front of it remain.
Main->Product Category->Product1->Subcategory->Product2
When clicking on Product1, only the chain
Main->Product Category->Product1 remains.
Now it is implemented so that when switching to a product, the product name is transferred to the breadcrumbs array using the push method.
I understand that something like this is needed:
var count = this.breadcrumbs.length;
this.breadcrumbs.pop(product, count);
On the selected element, the presence of class="active" is implemented, if anything.
Many thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-05-14
@Ksey123

<button v-for="(n, i) in items" @click="onClick(i)">{{ n }}</button>

methods: {
  onClick(index) {
    this.items = this.items.slice(0, index + 1);
    // или
    // this.items.splice(index + 1, this.items.length - index);
  },
  ...
},

https://jsfiddle.net/z3xh2ts4/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question