首页 文章

找不到模块:错误:'t resolve ' ./http-common'vue js axios

提问于
浏览
0

我使用本教程:https://alligator.io/vuejs/rest-api-axios/并尝试使用这样的axios:在我的main.js文件中:

import axios from 'axios'

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

在我的.vue文件中:

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)
                    })

错误在./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/components/SignIn.vue找不到模块:错误:可以'解决'C:\ Users \ direwolf \ Documents \ web \ js \ vue \ quasar-crm \ src \ components'@ ./node_modules/babel-loader/lib!./node_modules/vue中的'./http-common' -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 回答

  • 1

    you need to import from main.js

    import {HTTP} from './main';

  • 0

    尝试改变

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

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

    希望这在某些情况下有所帮助 .

相关问题