i cant access to value of a getterFunction on pinia

the function seems like work well and i can see the value but cant access to this getter function

i write this code to setup store value exist but can access to it

this store:
const pro = ref()
const getProductList = computed(() => pro.value)

const getProducts = (val1 = 'newest', val2 = '', val3 = 0, val4 = 0, val5 = 0, val6 = '', val7) => {
  pro.value = null
  axios.get('', {
      params: {
        sort: val1,
        title: val2,
        flash_id: '',
        max_price: val3,
        min_price: val4,
        available: val5,
        category_id: val6,
        vip: 0,
        attribute_value_id: [val7]
      }
    })
    .then((res) => {
      pro.value = res.data.data.products
      console.log(pro.value)
    })
    .catch(err => {
      console.log(err)
    })
}

and this console.log getter :
[The red line below the value is unavailable ][1]

when i try to enter its null

  • 1

    You say you can’t access data but you haven’t shown how. The screenshot (which should be posted as text not an image) shows the data, so how is it not accessible? Where is the code that’s trying to access it and failing? If you’re attempting to use the store in another component, you need to show that code. You also need to show all relevant pinia code. Getters need to be returned from setup stores, like anything else, and you’ve not shown whether or not you’re doing that.

    – 

  • what does cant access mean? do you get an error?

    – 

  • @JaromandaX X no i dont get error with this code getProductsList.value i try to enter to it but its null

    – 




  • perhaps const getProductList = computed(() => pro.value) is accessed using getProductList.value not getProductsList.value

    – 

  • It was a shot in the dark – you know how many questions are closed as typos?

    – 

Leave a Comment