0👍
You may use it like this:
const obj = reactive({products});
...
const searchedProducts =computed( () => {
return obj.products.filter(product => productId.includes(product.productId))
});
0👍
The reason why your getting the error is that your wrapping a ref()
inside of the reactive()
without the usage of an object so you are need to add an .value
to make it work like below. I made a StackBlitz to showcase.
const searchedProducts = computed(() => {
return obj.value.filter((product) => {
return product.id === productId;
});
});`
But you probably intended to do it like the example below to make the ref()
value unwrapped:
const obj = reactive({ products });
...
const searchedProducts = computed(() => {
return obj.products.filter((product) => {
return product.id === productId;
});
});
Two other things to point out:
- You are using
.includes()
to compare products ids. A strict comparison would be more reliable to use. - You forgot a return statement.
- [Vuejs]-How to run a function when the user clicks a RouterLink to the current path?
- [Vuejs]-How to keep the </a> closing tag on same line and all the others in new line in a Vue.js project?
Source:stackexchange.com