Skip to content
Advertisement

Vue 3: Why get same value before update object

I have 2 components in my project where I tried create query based search filter

  1. PostsList component:
JavaScript
  1. PostFilter component:
JavaScript

I must send one API request when filters is change/update. But why I get same values in activeFilters and in coming filters from method setFilters() of PostsList component on everytime?

Why I lose old value of activeFilters before set new values in my case?

You can see here real working example

Also here example video

JavaScript

Advertisement

Answer

The object references in chrome developer console is “alive”.

Consider this example:

JavaScript

this will output:

JavaScript

instead of Active filters {a: "b"}


You can use the spread operator to create a new object as value of activeFilters in your example to see different values:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement