[Vuejs]-Watch do not show variable changing

0👍

Disclaimer: I’ve though that you’re using .slice(). So as long as you’re use splice this answer isn’t valid. But I’ll keep it here for the record. Also the answer contain link to documentation.

Yes, .splice() updates array.


No, vuejs don’t track such array mutations:

According to documentation:

Vue.js wraps an observed Array’s mutation methods so they will also
trigger View updates. The wrapped methods are:

  • push()
  • pop()
  • shift()
  • unshift()
  • splice()
  • sort()
  • reverse()

And

filter(), concat() and slice(), which do not mutate the original Array but always return a new Array

So the idea is to replace you array with a new one:

example1.items = example1.items.filter(function (item) {
  return item.message.match(/Foo/)
})

Leave a comment