代码之家  ›  专栏  ›  技术社区  ›  Komang Suryadana

如何使用vue js而不在init上声明密钥数据

  •  1
  • Komang Suryadana  · 技术社区  · 8 年前

    我使用jquery与api rest进行通信数据。并使用vue js将数据渲染到我的模板,但我有一个错误。

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

    这是我的代码:

    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);
        });
    

    谢谢

    1 回复  |  直到 8 年前
        1
  •  5
  •   Bsalex    8 年前

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

    data: {
      newTodoText: '',
      visitCount: 0,
      hideCompletedTodos: false,
      todos: [],
      error: null
    }