Utilizing Axios Response Data in Vue JS to Enhance User Experience

Recently delved into Vue and not exactly a fan of Javascript, so I've set up a Vue component that uses Axios to fetch some data. However, I'm struggling to display this data in my form elements.

I have Axios intercepting the response and retrieving the necessary data:


  methods: {

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

    }
}

The above code is executed on page load, and here's what I have in my data section:

 
data() {
            return {
                formpersonaldetails: {},

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

However, as you can tell, this approach doesn't seem to be working. Can someone point out where I might be making a mistake?

Here's how the response data looks like:

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

Answer №1

To properly utilize the function, it is necessary to provide the response as an input:

axios.interceptors.response.use(function (response) {
    // Manipulate response data here
    return response;
  }, function (error) {
    // Handle any errors in the response
    return Promise.reject(error);
  });

For further details, please refer to: Axios

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is preventing me from running my alert script in JavaScript?

Need some assistance here. I have a simple question. I am trying to create an alert function using JavaScript, but it is not working. <script type="text/javascript"> $(".delete").click(function(){ alert("Are you sure?&q ...

Tips for increasing visibility for your Google Analytics Embed API Custom Components

I recently tried to incorporate some code I found at the following link: After downloading the files view-selector2 and date-range-selector, I saved them in my local directory. I made a modification to the code: var accountSummaries = require(['&ap ...

Verify if there are DOM elements located within a DIV container, execute the functions associated with those elements sequentially

I am in the process of creating a game using HTML, CSS, and JavaScript. My focus right now is on manipulating DOM elements without relying on the canvas tag. The goal is to develop a pseudo graphical programming language, similar to the environment provide ...

Simplified jQuery function for multiple div mouseover operations

Uncertain about the accuracy of my title. Due to certain reasons, I need to assign different IDs for the class, as it only detects ID and not class when hovered over. Therefore, I have created a CSS version where the opacity of a specific div will change t ...

Angular Directive may encounter compatibility issues in Internet Explorer

My journey into learning AngularJS has led me to successfully create a web application using Google Charts and Angular. Everything was running smoothly in Firefox and Chrome until I decided to test it in Internet Explorer (IE) and discovered that my projec ...

What steps should I take to create a JavaScript-based downloader application?

I am looking for a way to sell some files from my Web Server to clients. I have created my own HTTP server and I have experience programming in HTML, CSS, and a little bit of JavaScript. While I have seen tutorials on creating download links with HTML 5, I ...

Tips for successfully passing an array containing multiple values within the jsPDF body

I'm experimenting with jsPDF to showcase a list of products that users have ordered. I've managed to set up my columns and generate the PDF for download, but I'm facing some challenges with populating the body section. When attempting to sen ...

Is there a way for me to calculate the square of a number generated by a function?

Just starting out with Javascript and coding, I'm having trouble squaring a number that comes from a function. I've outlined below what I am trying to achieve. Thank you in advance for your help. // CONVERT BINARY TO DECIMAL // (100110)2 > ( ...

Being required to design a distinct div for every article I am extracting from the API

In the midst of developing a website for my college project, I have successfully configured my news API to pull and display data using JavaScript. Currently, I am faced with the challenge of having to create separate div elements each time I want to add n ...

Parsing JSON data using PHP and AJAX decoding

I have been searching for a way to pass parameters between the server and client, but I am struggling to find a solution that works. Despite reading extensively online, I have not been able to come up with a functioning solution. Client Side function sen ...

Highlighting the Active Navigation Menu for the Current Page Using a Unified Header File

Is there a way to highlight the navigation menu for the current page I am visiting? header.php <div class="header-menu"> <div class="nav"> <ul> <a href="index.php"><li>Home</li> ...

Error in parsing string data in Django Chart.js ajax using javascript

I'm currently working on creating a chart web page using Django and Chart.js within the views.py file of the Django framework. class ChartView(TemplateView): template_name = 'graph.html' def get_context_data(self, **kwargs): ...

Quickest method for skimming through an extremely lengthy document beginning at any specified line X

In my current project, there is a text file that is written to by a python program and read by another program to display on a web browser. JavaScript handles the reading process at the moment, but I am considering moving this functionality to python. The ...

Struggle with implementing enums correctly in ngSwitch

Within my application, I have implemented three buttons that each display a different list. To control which list is presented using Angular's ngSwitch, I decided to incorporate enums. However, I encountered an error in the process. The TypeScript co ...

Tips for creating a function that utilizes a select option value

I'm struggling with a form that includes two select inputs. I want the second input to only be enabled if the first one has been selected. I attempted using an onclick event, but it didn't work out as expected. Can anyone provide assistance? (apo ...

Tips for managing the onblur event using selenium automation framework

I want to trigger an onblur event when I click away using JavaScript. I tried the following code: ((JavascriptExecutor)getDriverProvider().executeScript("document.getElementByXpath('xpath here').onblur();"); However, it doesn't seem to wo ...

"Eliminate the headers of columns within the collapsible rows on the ui-grid interface

I am working with an expandable table and trying to figure out how to hide the column headers for only the expandable rows within the table. I experimented with including showHeader : false in the subGridOptions, but without success as the headers are stil ...

The use of props in mapState may result in unexpected behavior in Vue.js

When trying to pass a value from props and use it as the namespace in mapState, an error occurs: 'Error while initializing app TypeError: Cannot read property 'store' of undefined' Here is the code snippet: In the ParentComponent: < ...

What is the best way to trigger a mongoose post hook from a separate JavaScript file or function?

I've been working with a location.model.js file that looks like this: 'use strict'; var mongoose = require('mongoose'), Schema = mongoose.Schema; var LocationsSchema = new Schema({ name: String, description: String, country_i ...

Jasmine attempting to access a nonexistent property

I created a very basic component: import { Component } from '@angular/core'; @Component({ selector: 'loading', templateUrl: './loading.component.html', styleUrls: ['./loading.component.scss'] }) export ...