NuxtN
Nuxt2y ago
serafina

useAsyncData + pinia store field

There is such a situation:
  1. Component.vue:
<script setup>
const { localData} = storeToRefs(piniaStore());

await useAsyncData(async () => piniaStore().init());
</script>

<template>
<div v-if=“localeData?.length></div>
</template>

  1. Store:
const localData = ref<null | string[]>

const getLocalData() = async () => {
const { data } = $fetch()

(This is where everything comes in and in the project console I can see data, but the value is not set and therefore there is nothing on the page, there is a v-if)

localData.value = data;
}

const init = async () => Promise.all([getLocalData()])

The question is, what is it? Maybe I can read something, I've already reread the docks three times on useAsyncData, but the watch cases there don't suit me, because I set the store field, but it always remains empty.
Was this page helpful?