Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
How to get state in Nuxt js Store component?

I use Nuxtjs composition api for my project . And i wanna make my code more dynamic

Inside state object; news, world, sports... are kept datas of visited page.

state.js file

subCategoryColumnsData: { news: [], world: [], sports: [], economy: [], technology: [], life: [] },

mutation.js file

state.subCategoryColumnsData[subCategoryName] = [...getColumnsData]

category.vue

setup()
{
const columns = computed(() => store.state['subCategory'].subCategoryColumnsData[subCategoryName.value]);

const { fetch } = useFetch(async () => {
     await store.dispatch('subCategory/getColumnsQuery', 
        categories: categoryId.value, //keeps id of page 
        subCategoryName: subCategoryName.value, // to keep news, world ,sport etc page names
      });

}

Above code works without any mistake.

I can increase my page counts so i need to update subCategoryColumnsData every time. So I want to make my code more dynamic. So i changed it to:

state.js file

subCategoryColumnsData: {},

mutation.js file

state.subCategoryColumnsData[subCategoryName] = [...getColumnsData]
// this creates already something like this subCategoryColumnsData: { news: [....data], world: [] ,.... }, when web pages changed

category.vue

const columns = computed(() => store.state['subCategory'].subCategoryColumnsData[subCategoryName.value]);

when i called my state , it returns undefined. But my state is full.
when i checked store. 
If i visit another page and come to same page again, then i can see data this time . 

But if i call my state like this=>
const columns = computed(() => store.state['subCategory'].subCategoryColumnsData) 

i can see my state datas. But this includes every visited page datas. 
When i wanted to filter by adding [subCategoryName.value] , i can't reach again . It returns undefined again. 

I want to understand why i cant reach my state when i visited my page for the first time

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda