在测试接口请求函数时报错
<script>
import FooterGuide from "./components/FooterGuide/FooterGuide";
import {reqFoodcategorys} from "@/api";
export default {
name: 'App',
async mounted(){
const result = await reqFoodcategorys()
console.log(result)
},
components: {
FooterGuide
}
}
</script>
/*
* 包含n个接口请求函数的模块
* 函数的返回值:promise对象*/
//根据接口文档定义接口请求函数
import ajax from './ajax'
const BASE_URL = 'api'
// [1、根据经纬度获取位置详情]
export const reqAddress = (geohash) => ajax(`${BASE_URL}/position/${geohash}`) //geohash为参数
// [2、获取食品分类列表]
export const reqFoodcategorys = () => ajax(BASE_URL+'/index_category')
// [3、根据经纬度获取商铺列表]
export const reqShops = (longitude,latitude) => ajax(BASE_URL+'/shops',{longitude,latitude})
// [4、根据经纬度和关键字搜索商铺列表]
报错
vue.runtime.esm.js:4609 [Vue warn]: Error in mounted hook (Promise/async): "TypeError: (0 , _ajax__WEBPACK_IMPORTED_MODULE_0__.default) is not a function"
found in
---> <App> at src/App.vue
<Root>
warn @ vue.runtime.esm.js:4609
logError @ vue.runtime.esm.js:3045
globalHandleError @ vue.runtime.esm.js:3041
handleError @ vue.runtime.esm.js:3008
eval @ vue.runtime.esm.js:3019
Promise.catch (async)
invokeWithErrorHandling @ vue.runtime.esm.js:3019
callHook$1 @ vue.runtime.esm.js:4032
insert @ vue.runtime.esm.js:4427
invokeInsertHook @ vue.runtime.esm.js:6946
patch @ vue.runtime.esm.js:7160
Vue._update @ vue.runtime.esm.js:3765
updateComponent @ vue.runtime.esm.js:3875
Watcher.get @ vue.runtime.esm.js:3446
Watcher @ vue.runtime.esm.js:3436
mountComponent @ vue.runtime.esm.js:3892
Vue.$mount @ vue.runtime.esm.js:8779
Vue._init @ vue.runtime.esm.js:5705
Vue @ vue.runtime.esm.js:5766
eval @ main.js:7
./src/main.js @ app.js:743
__webpack_require__ @ app.js:1544
(anonymous) @ app.js:2666
__webpack_require__.O @ app.js:1590
(anonymous) @ app.js:2667
(anonymous) @ app.js:2669
vue.runtime.esm.js:3049 TypeError: (0 , _ajax__WEBPACK_IMPORTED_MODULE_0__.default) is not a function
at reqFoodcategorys (index.js:16:1)
at VueComponent.mounted (App.vue:16:1)
at invokeWithErrorHandling (vue.runtime.esm.js:3017:1)
at callHook$1 (vue.runtime.esm.js:4032:1)
at Object.insert (vue.runtime.esm.js:4427:1)
at invokeInsertHook (vue.runtime.esm.js:6946:1)
at Vue.patch [as __patch__] (vue.runtime.esm.js:7160:1)
at Vue._update (vue.runtime.esm.js:3765:1)
at Vue.updateComponent (vue.runtime.esm.js:3875:1)
at Watcher.get (vue.runtime.esm.js:3446:1)