Axios 响应数据和 Vue JS ,使用数据
Axios Response data and Vue JS , Using the data
Vue 的新手并且不太喜欢 Javascript 所以我有一个 Vue 组件,它使用 Axios 来获取我在控制台中的一些数据。我根本无法将代码输出到我的表单元素。
所以我有 Axios 拦截响应并获取数据
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"}
您需要将 response
传递给 function
:
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
Vue 的新手并且不太喜欢 Javascript 所以我有一个 Vue 组件,它使用 Axios 来获取我在控制台中的一些数据。我根本无法将代码输出到我的表单元素。
所以我有 Axios 拦截响应并获取数据
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"}
您需要将 response
传递给 function
:
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