ES6导入语法,遇到不同模块的同名导出对象怎么解决

147 阅读1分钟

解决方法:
使用 import xxx as xxx from '@/xxx'语法
如果subjects.js / directorys / companys三个文件都导出了 list 方法

import { list as subjectsList } from '@/api/hmmm/subjects'
import { list as directorysList } from '@/api/hmmm/directorys'
import { list as companysList } from '@/api/hmmm/companys'

除此之位,import * as xxx from '@/xxx' 的用法也很常见,意思是导入全部按需导出的对象,比如echarts的导入就需要这种语法