【发布时间】:2020-06-24 19:36:29
【问题描述】:
我正在尝试使用 axios 为 API 提供通用服务
api.js
import axios from 'axios'
export default () => {
return axios.create({
baseURL: `${window.location.origin}/`
})
}
authenticationService.js
import api from '@/services/api.js'
export default {
login(credentials) {
return api.post('...', credentials)
}
}
vuex 动作
import authenticationService from '@/services/authentication/authenticationService'
async login({commit}, credentials) {
try {
let response = await authenticationService.login(credentials)
console.log(response)
} catch(er) {
console.log(er)
}
})
我遇到了错误*
_services_api__WEBPACK_IMPORTED_MODULE_0__.post is not a function
at Object.login (authenticationService.js:6)
当我展开时:
login: function login(credentials) {
return _services_api__WEBPACK_IMPORTED_MODULE_0__["post"]('...', credentials);
}
看起来它没有正确导入创建 axios 的 api 函数?
【问题讨论】:
标签: javascript api vue.js request axios