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

187
Views
Undefined proprety, since it already exists

I'm working with VueJs / Vuex using Laravel in the backend. I'm getting undefined error message each time in my console.

This is my state.js

var state = {
 data: {
    record:{
        data:{}
    }
  }
}
export default state;

This is my component :

computed: {
    ...mapState({
        data: (state) => state.data,
    }),
    record: function(){
         return this.data.record.data.profile[0];
    }
},

How I try to display data :

<h4>{{record.name}}</h4>

This is my Vuex from (Vuex DevTools)

{
"record":{
  "data":{
     "profile":[
        {
           "id":6,
           "name":"bret.prohaska",
           "email":"delta00@example.org"
        }
     ]
  }
}
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

profile is undefined before data is loaded, which will throw undefined error if you try to index it. You need to take care of the edge case in your logic:

record: function(){
  let profile = this.data.record.data.profile
  return profile ? profile[0] : {};
}
about 4 years ago · Juan Pablo Isaza Report
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!