1

I use jquery for communication data with api rest.And use vue js for rendering data to my template, but i have error.

[Vue warn]: Error in render function: "TypeError: Cannot read property 'first_name' of undefined"

This my code :

var dashboard = new Vue({
  el: '#dashboard',
  data:{
    profile: {}
  }
});
axios.get(url_profile, { headers: {"Authorization": "JWT " + token} })
    .then(function(res){
        dashboard.$data.profile = res.data;
    })
    .catch(function(err){
        toastr.err(err);
    });

Thanks.

3
  • 1
    What about your code? Commented Oct 11, 2017 at 9:34
  • 2
    Please make sure your question includes a minimal reproducible example. Commented Oct 11, 2017 at 9:37
  • What is the object with first_name attribute? Commented Oct 11, 2017 at 9:45

1 Answer 1

5

https://v2.vuejs.org/v2/guide/instance.html#Data-and-Methods

If you know you’ll need a property later, but it starts out empty or non-existent, you’ll need to set some initial value. For example:

data: {
  newTodoText: '',
  visitCount: 0,
  hideCompletedTodos: false,
  todos: [],
  error: null
}
Sign up to request clarification or add additional context in comments.

1 Comment

you can help me with full example, i dont understand. I add el: '#dashboard', data:{ profile: Object, newTodoText: '', visitCount: 0, hideCompletedTodos: false, todos: [], error: null } still error :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.