TypeError: 'set' on proxy: trap returned falsish for property 'X' #1027
Answered
by
soc221b
michealroberts
asked this question in
Help and Questions
-
I have the following store defined:
Let's say I have my productStore defined in setup as follows:
When I essentially call (FWIW, the products are coming back from an API as blank) Expected behaviorNo error, I should be able to set my products to an empty array without issue. Actual behaviorI see the following error:
Additional informationpinia version 2.0.11 |
Beta Was this translation helpful? Give feedback.
Answered by
soc221b
Feb 4, 2022
Replies: 1 comment 7 replies
-
You should not use the same name in state, getters, actions, use this instead: export const useProductsStore = defineStore('products', {
state: () => ({
- products: [] as Product[]
+ _products: [] as Product[]
}),
getters: {
- products: (state) => state.products
+ products: (state) => state._products
},
actions: {
setProducts(products: Product[]) {
- this.products = products
+ this._products = products
}
}
}) or export const useProductsStore = defineStore('products', () => {
const products = ref<Product[]>([])
const setProducts = (_products: Product[]) => {
products.value = _products
}
return {
products: computed(() => products.value),
setProducts,
}
}) |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
michealroberts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should not use the same name in state, getters, actions, use this instead:
or