鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ export default 和 module.exports 等效嗎?

export default 和 module.exports 等效嗎?

directive.js

const install = (Vue) => {
    //...
    };
export default { install, fun } // 1.
module.exports = { install, fun } // 2.

// main.js

import directives from './directives';
let install = directives.install;
let fun = directives.fun;

以上兩種導(dǎo)出是等效的嗎?

回答
編輯回答
浪蕩不羈

export 指向 module.export
export default === export.default
import 的時候會默認(rèn)導(dǎo)入 default
如果沒有 default 會導(dǎo)入 所有的export值,需要用 * as name,或者{name}來接收

2017年12月13日 19:07
編輯回答
你好胸

都屬于導(dǎo)出模塊

但是有點(diǎn)區(qū)別 exports 是module模塊的一個屬性 exports變量是指向module.exports,加載模塊實(shí)際是加載該模塊的module.exports 一般為require導(dǎo)入

export default命令,為模塊指定默認(rèn)輸出,默認(rèn)導(dǎo)出一個整體接口 一般為import導(dǎo)入

2017年3月1日 11:34