Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!