Skip to content
Advertisement

Data becoming a proxy when trying to make a SearchBar with vue3

i have an application made with VueJs3, and i trying to make a searchbar based on .filter(), and it seems to be working, but when i try to pass te value from my methods to my template its making a huge error, my data is becoming a proxy, and i cant use the data in a proxy format.

The code:

JavaScript

The code refering to the search bar is between the lines 2-5 and 35-65.

The console.log(filteredArray); in line 64 return this:

JavaScript

And i recieve the error in lines 17-22 after i user the function filterList:

JavaScript

Advertisement

Answer

The fact that a value changes to a proxy should not be causing any issues.

The issue is that you are using const filtered = myListArray.find(...). The result of find is either a null or the first object in the array that matches your criteria, so filteredArray will never have an array as the content. When you pass it to the template though, you use for in so the iterator will go through your objects’ properties (ie item at some point will be attributes, so attributes.attributes will be unefined, ergo attributes.attributes.image throws an error.

You probably meant to use filter instead of find

JavaScript

I think the solution is a bit overcomplicated here

you can use v-model for the search input and the filtered dataset can use a computed

example: (SFC)

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