Home

Issue: 2006

How to get data from local json file using actions and axios.get()?

[issue link]

I wrote Action, that should get data from db.json file. But I get: “xhr.js:178 GET http://localhost:8083/data/db.json 404 (Not Found)”.
Why is it, if my path is correct (db.json is in the same folder)?
In profileActions.js:

import axios from "axios";
var customData = require('./db.json');

export function fetchUsers(){
    return function(dispatch){
        axios.get('./db.json')
            .then((response) => {
                dispatch({type:'FETCH_USERS_FULFILLED', payload:response.data});
            })
            .catch((err) => {
                dispatch({type:'FETCH_USERS_REJECTED', payload:err});
            })
    }
}
This question is available on Nuxt.js community (#c1782)