首页 文章

Axios Response数据和Vue JS,使用数据

提问于
浏览
0

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"}

1 回答

  • 0

    您需要将 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

相关问题