1

I use this tutorial: https://alligator.io/vuejs/rest-api-axios/ And tried to use axios like this: in my main.js file:

import axios from 'axios'

export const HTTP = axios.create({
    baseURL: `http://api.com/api/`,
    headers: {
        // Authorization: 'Bearer {token}'
    }
})

And in my .vue file:

import {HTTP} from './http-common';
let params = {
                    email: this.login,
                    pwd: this.pwd
                }
                HTTP.post(`login`, params)
                    .then(response => {
                        alert(response);
                    })
                    .catch(e => {
                        this.errors.push(e)
                    })

ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/components/SignIn.vue Module not found: Error: Can't resolve './http-common' in 'C:\Users\direwolf\Documents\web\js\vue\quasar-crm\src\components' @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/components/SignIn.vue 5:0-37 @ ./src/components/SignIn.vue @ ./src/router.js @ ./src/main.js @ multi ./build/hot-reload.js ./src/main.js

2 Answers 2

2

you need to import from main.js

import {HTTP} from './main';

Sign up to request clarification or add additional context in comments.

Comments

0

Try changing

import {HTTP} from './http-common'; to

import {HTTP} from '../http-common';

Hope this helps in some cases.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.