开发中遇到的一个简单问题 却花了我很长时间

//在一个js文件中导出fetch请求方法
import fetch from 'utils/fetch';
 
export function getCompanyList() {
  return fetch({
    url: '/wx/company/list',
    method: 'get'
  })
}

 

//在vue的script代码块中导出
import getCompanyList from 'api/recruitManage/index';
 
//调用请求
  methods: {
    getList() {
      getCompanyList().then(res => {
        if (res.errno == 0) {
          this.companys = res.data
        }
      });
    }
  }


编译时警告:

 warning  in ./src/views/oa/recruitManage/index.vue

23:6-20 "export 'default' (imported as 'getCompanyList') was not found in 'api/recruitManage/index'

一开始没看到警告 请求时报错 

[Vue warn]: Error in v-on handler: "TypeError: __webpack_require__.i(...) is not a function"
 
TypeError: __webpack_require__.i(...) is not a function


试了很久没有解决 最后发现时import语法问题

//在import后面加上大括号解决
import {getCompanyList} from 'api/recruitManage/index';


import,export语法规范详解:http://es6.ruanyifeng.com/#docs/module#export

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐