2017-10-11 59 views
0

Vue的新用户并没有太多的Javascript爱好者,所以我有一个Vue组件,它们使用Axios来获取控制台中的一些数据。我只是不能将代码发送到我的表单元素。Axios响应数据和Vue JS,使用数据

所以我爱可信截获响应和获取数据

methods: { 

    }, 
    mounted: function() { 
     axios.interceptors.response.use(function (response) { 
      return response.data; 
     }); 
    }, 
    destroyed: function() { 

    } 
} 

使安装在页面加载和我的数据我有

data() { 
      return { 
       formpersonaldetails: {}, 

       title: this.results.title, 
       titleoptions: ['Mr', 'Mrs', 'Miss', 'Ms'], 
       fname: this.results.fname, 
       sname: this.results.sname, 
       dob: this.results.dob, 

正如你能猜到不工作,所以我哪里错了?

响应看起来像这样:

{"id":2,"user_id":null,"fname":"Graham","sname":"Morby-Raybould","dob":"1982-07-10T08:22:00.000Z","gender":"Male","nationality":"British","mobile":null,"telephone":null,"hname":"","address2":"","address3":"","postcode":"","noktitle":"","nokfname":"","noksname":"","nokcontactnumber":"","nokhname":"","nokaddress2":"","nokaddress3":"","nokpostcode":"","emp_type":"","trade":"","ninumber":"","utrnumber":"","vatreg":null,"vatcert":"","created_at":"2017-10-10 08:22:37","updated_at":"2017-10-10 08:22:37"} 
+0

它不会因为当你收到可能工作从axios的反应你没有做任何进一步的事情。您会希望将响应数据映射到组件的数据对象中,但是当然,因为我们不知道您的响应是什么,所以我们无法告诉您如何将该响应合并到您的预先存在的数据中。 – Terry

+0

我加我对帖子的回复Terry – GrahamMorbyDojo

回答

0

你需要传递responsefunction

axios.interceptors.response.use(function (response) { 
    // Do something with response data 
    return response; 
    }, function (error) { 
    // Do something with response error 
    return Promise.reject(error); 
    }); 

点击此处了解详情:Axios

+0

所以我改变了这一点,你将如何在数据中使用它? – GrahamMorbyDojo

+0

你存储响应数据的地方? –