M
M
mrFlyer2019-02-08 12:36:24
JavaScript
mrFlyer, 2019-02-08 12:36:24

How can I access an instance of the axios class inside another class in Nuxt?

Good afternoon. Trivial question and stupid.
There is an SSR app on NUXT. I don't understand how to get an axios class instance inside a class method.
Axios is connected to nuxt.config.js, in components I work with it normally through this.$axios, but as in a class I can’t catch up.

export default class CustomClass {

    constructor(config) {
        this.config = config;
    }

    /**
     * @returns {Promise}
     */
    send() {
        return new Promise((resolve, reject) => {
// как тут обратиться к нему? в компоненте this.$axios, а тут не пойму.
            axios.request(this.config)
                .then((response) => {
                    return resolve(new Response(response));
                })
                .catch((error) => {
                    return reject(new RequestError(error, new Response(error.response)));
                });
        });
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question