0👍
✅
Thats because you are slicing the searchHistory
array and getting only the last 5 elements, and you also reverse the array here:
v-for="(item, index) in searchHistory
.slice(-5)
.reverse()
.map((s) => s.trim())"
The index
value on the loop will be the index on this new array, so when you do:
this.searchHistory[index];
It won’t get the right one.
You can fix the logic there or do something like:
this.search = this.searchHistory.slice(-5).reverse()[index];
UPDATE
As pointed out by @Lawrence Cherone in his response, you can just do:
@click="selectPreviousSearch(item)"
if you need the value of this.search
to be trimmed, it will work just fine like that.
Source:stackexchange.com