export与model.export有啥区别

关于exportexport default 的常用方法

一个js文件中,最多只能有一个export default,可以同时有多个export
看一下下面的例子

1、只有一个export时,应使用export default,而不能使用使用export

class myComp {
 ...
}
export default myComp

对应的import为 import MyComp from './myComp'

2、有多个需要export时

export function fun1(){ }
export function fun2(){ }

or

function fun1(){}
function fun2(){}
export {fun1, fun2}

对应的import为import {fun1, fun2} from './myComp'

3、如何使用export import连用

export { default as MyComp } from './myComp'

module.export与 export出来的有什么区别呢

# conf.js
module.exports = {
	abc: '123',
	ddd: '123',
}

对应的import为import { abc, ddd } from './conf.'

# conf.js
export default {
	abc: '123',
	ddd: '123',
}

对应的import为import Conf from './conf'

ps:不能使用 import { abc, ddd } from ‘./conf’

发布了132 篇原创文章 · 获赞 7 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/youlinhuanyan/article/details/105211072