我使用本教程: 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 找不到模块:错误:无法解析' ./ http-common'在 ' C:\用户\冰原狼\文件\网络\ JS \ VUE \类星体-CRM \ SRC \部件' @ ./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
答案 0 :(得分:1)
您需要从main.js
导入 import {HTTP} from './main';
答案 1 :(得分:0)
尝试更改
import {HTTP} from './http-common';
至
import {HTTP} from '../http-common';
希望这在某些情况下会有所帮助。