杂记3

1.module.exports
**exports **返回的是模块函数
**module.exports **返回的是模块对象本身,返回的是一个类
在vue-cli项目中用到了module.exports,作为萌新搜索了网上的前端学习博客,我认为可以简单的将其理解为类似于类的声明,其他js代码想要用到声明了module.exports的部分,只需要new一个对象即可。
hello2.js

module.exports = function(name,age,money) {
  this.name = name;
  this.age = age;
  this.money = money;
  this.say = function() {
    console.log('我的名字叫:'+this.name+',我今年'+this.age+'岁,月薪为:'+this.money+'元;')
  }
};
var Hello2 = require('./hello2');
var hello2 = new Hello2('hello2','28','10000')
hello2.say(); 

显示结果:
我的名字叫:hello2,我今年28岁,月薪为:10000元

vue.config.js 当然也是作为这样一个类被调用的,吧。鉴于没有搜索到vue.config.js在项目中被显示的调用,应该认为是直接被框架调用了。官方文档中说明会被@vue/cli-service自动加载

原文地址:https://www.cnblogs.com/bestefforts/p/11908336.html