[Bug0027] vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in created hook: "TypeError: this.$api.listRole is not a function"

1、问题

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in created hook: "TypeError: this.$api.listRole is not a function"

found in

---> <Role> at src/views/xxx/role/index.vue
       <AppMain> at src/layout/components/AppMain.vue
         <Layout> at src/layout/index.vue
           <App> at src/App.vue
             <Root>

2、场景

写好后端接口,就打算用若依框架代码生成试试生成的前端页面,结果前端页面找刷新不出来

3、原因

技术新手 C 代码少 C 了一部分,由于项目请求接口进行了封装,我只复制了 Api 部分,所以导致函数请求时报错 this.$api.listRole is not a function

前端目录结构

图一

图二

4、解决方案

在index.js文件中类似图一图二如下添加封装好接口即可。

import * as xxxUserApi from './xxx/user'

export default {
  ...xxxUserApi,
}
posted @ 2022-07-07 18:01  Code7Rain  阅读(757)  评论(0编辑  收藏  举报