美文网首页
require/module/exports

require/module/exports

作者: LynnLiu_ | 来源:发表于2019-11-21 17:50 被阅读0次

require(string path)

引入模块。返回模块用过module.exportsexports暴露的接口。

path:需要引入的模块文件相对于当前文件的相对路径,或是npm模块名,或是npm模块路径。不支持绝对路径

//common.js
function sayH(name) {
  console.log('Hello ${name} ! ')
}

function sayGoodbye(name) {
  console.log('Goodbye ${name} ! ')
}

module.exports.sayH = sayH
exports.sayGoodbye = sayGoodbye
const common = require('common.js')
Page({
  helloMINA() {
    common.sayH('MINA');
  },
  goodbyeMINA() {
    common.sayGoodbye('MINA');
  }
})

Object module

module的类型是object,其实模块向外暴露的对象,使用require引用该模块时可以获取

相关文章

网友评论

      本文标题:require/module/exports

      本文链接:https://www.haomeiwen.com/subject/wuwmoqtx.html