Skip to content

TypeError: 'set' on proxy: trap returned falsish for property 'X' #1027

Discussion options

You must be logged in to vote

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

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@posva
Comment options

@boxshadow
Comment options

@zarka07
Comment options

@arnonrdp
Comment options

@doox911
Comment options

Answer selected by michealroberts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
8 participants
Converted from issue

This discussion was converted from issue #1026 on February 03, 2022 22:31.