其实简单来说,就是不同的框架规范,导致了这三个使用上的混淆。
CommonJS规范
node模块中,采用的是CommonJS规范,使用module.exports导出接口。
使用require引入模块。
var vue= require('vue'); |
ES6写法:
ES6标准发布后,module成为标准,标准使用是以export指令导出接口,以import引入模块。
export default { data() { return { name:"jet", } }, methods:{ getname:function(){ if(this.name==""){ this.name="jet"; return this.name; }else{ return this.name; } } } } import jet from "jet.vue"; |
也就是说,
NodeJS等CommonJS规范使用module.exports require来暴露组件成员
ES6使用export import来暴露组件成员