Nuxt's axios is encountering difficulties in managing the server's response

Having just started working with Nuxt.js, I encountered an unusual issue. There is an endpoint in my backend API that allows users to reset their password by sending a token along with a new password.

Although the request is being sent correctly and the server responds with the expected data:

https://i.sstatic.net/gAWsq.png

The problem arises on the Nuxt.js side when handling the response data.

To manage all HTTP requests using axios, I have implemented a class like this:

class WebAPI {
    // $axios is the instance used in the Nuxt.js context
    constructor($axios) {
        this.$http = $axios;
    }

    async call(config) {
        try {
            const result = await this.$http(config);
            console.log(result);
            // ...
        } catch( e) {
            // ...
        }
    }
}

And I utilize this class as follows:

const data = {
    token,
    new_password
};

const options = {
    method: 'POST',
    url   : '/reset-password',
    data
};

return this.webApi.call(options);

However, as you can see, the issue lies within the WebAPI service where the axios response is showing as undefined.

It is also important to note that the same WebAPI class functions perfectly for other API requests made in the application.

Can anyone assist with this matter? Is there anything that stands out as incorrect?

Answer №1

It appears that your implementation of axios may be incorrect. Consider utilizing the $request method instead, as demonstrated below:

async fetchData(config) {
  try {
    const response = await this.$http.$request(config);
    console.log(response);
    // Additional operations...
  } catch(error) {
    // Error handling...
  }
}

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

The div element with the id "wrapper" is not functioning properly within the box model

I have defined an ID wrapper in CSS: #wrapper { position: relative; background: yellow; -webkit-box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.2); box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.2); width: 960px; padding: 40px 35px 35px ...

Unable to locate the module 'vuetify-loader/lib/plugin'

After installing vuetify through vue-cli3, I encountered an error when running npm run serve, indicating a missing loader. I have searched through documentation and various sources but have not found a solution. This is a new project with no additional c ...

Navigate or scroll to anchors within Vue Router by using the hashtag followed by the anchor name

I am encountering an issue with vue-router where it is not scrolling/navigating to anchor tags (e.g. #anchor). I have explored multiple solutions on Stack Overflow, but none have proven effective thus far. Below is the code snippet that I am currently usi ...

The JavaScript function exclusively reveals the final element, which is Three.js

I'm currently working on a fence generator function using Three.js, but for some reason, my function is only returning the last fence created. It's really puzzling to me... function createFence(nb){ var i; var position = -5; var loadingMan ...

Creating a line between two points in raphael

Hello there, I'm looking to create a line between two points in Raphael. Could you please provide me with some examples or guidance on how to achieve this? Thanks a lot!) ...

React fails to respond to the .click() method

I believe the .click function originates from jQuery, but I came across it being used in pure JavaScript as well. This makes me wonder if I can utilize it in my React code too. The scenario where I want to incorporate it is as follows: keyUpFunction(even ...

VUE and Axios: Issue with Request Header Content-Encoding Disallowed by Access-Control-Allow-Headers in Preflight Response

Currently, I am working on creating a quick web application for fun that utilizes the League of Legends API. While some API calls are successful, I am encountering an issue with one specific message stating: "Request header field content-encoding is not a ...

What is the reason behind WP AJAX consistently returning a value of 0?

Having trouble retrieving a proper response, as it always returns 0. Here is the JavaScript code in the head section: q = new XMLHttpRequest(); q.open('POST', ajaxUrl); q.onreadystatechange = function () { if (q.readyState === 4) { ...

The impact of Ajax on jQuery document loading within an Ajax form

I'm currently using jQuery to change the colors of cancelled bookings in a Drupal view, and it's working well. jQuery(document).ready(function(){ jQuery(".bookingstatus:contains('Cancelled')").css("color","red"); }); However, when ...

Prevent zooming or controlling the lens in UIWebview while still allowing user selection

Is there a way to disable the zoom/lens on uiwebview without affecting user selection? I'm trying to avoid using "-webkit-user-select:none" in my css. -webkit-user-select:none ...

Polymer element created specifically for this project can be seen in the DOM, yet it does not display any content within the

Snippet: <link rel="import" href="../../../../bower_components/polymer/polymer.html"> <link rel="import" href="../../../../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html"> <dom-module id="app-index"> <templa ...

The utilization of count variable is not permitted in embedded array lookup

I've been using C# for quite some time, but I'm facing a challenge with a basic concept in the JavaScript part of my project. The following code snippet is part of a larger function I've written: addPaymentsToBreakdown = function () { f ...

Different approach for binding in Vue.js

Seeking Alternatives I am curious to find out if Vue.js offers a different approach for outputting data beyond the conventional curly braces. Is there a syntax similar to Angular's ng-bind directive that I could utilize? Although Vue.js primarily ut ...

Traversing through objects in react.js

Hello there, I'm currently learning React and JavaScript but facing some challenges with a particular task. Let's dive into it! So, imagine I have an array like this: clients = ["Alex", "Jimmy"] and then I proceed to create another array using th ...

Check if an array includes a specific value, and then either update it if found, or create it

I'm currently working with a Cart object in Javascript and I need to check if a specific item is present in the cart. Here's my approach: If the item is already in the cart, update its quantity. If it's not in the cart, add it to the items ...

Retrieve a specific value in HTML <a> tag using JavaScript-Ajax in Django

I am currently working with Python 3 and Django. Within my HTML code, I have the following: {% for category in categories() %} <li class="c-menu__item fs-xsmall"> <a href="#" id="next-category"> {{ category}} & ...

Is it possible to integrate Google Analytics with Next.js version 13?

Is there anyone who has successfully integrated Google Analytics with NextJS 13? I tried following the steps outlined in this thread: How to implement Google Analytics with NextJS 13?, but despite doing everything as instructed, I am not seeing any data o ...

Tips for determining the minimum value within an array of objects across multiple keys using a single function

I am currently tasked with the challenge of determining the minimum value from an array of objects that contain multiple keys. My ultimate goal is to identify the minimum value among all keys or specific keys within the objects. For instance var users = ...

I encountered an error of "Unexpected token '>'" while working with an

My code includes an ajax call and utilizes promises in the function: element.on("keypress", ".keyEvents", function(event) { if (event.which == 13) { // create the url and json object var putUrl = ...

PHP encountering a bad escaped character while parsing JSON using JSON.parse

I'm encountering an issue with JSON parsing. In my PHP code, I have the following: json_encode(getTeams(),JSON_HEX_APOS); This returns a large amount of data. Sample data: To provide more clarity, let's assume I have this: my_encoded_data ...