zoukankan      html  css  js  c++  java
  • 小程序-模块化

    require

      any require(string path)
      引入模块。返回模块通过module.exports或exports暴露的接口。

    参数
    名称 类型 说明
    path string 需要引入模块文件相对于当前文件的相对路径,或npm模块名,或npm模块路径。不支持绝对路径

    示例代码:
                // common.js
                function sayHello(name){
                    console.log(`hello ${name}`)
                }
                function sayGoodbye(name){
                    console.log(`goodbye ${name}`)
                }
                module.exports.sayHello=sayHello
                exports.sayGoodbye=sayGoodbye
    
                var common=require("common.js")
                Page({
                    helloMINA:function(){
                        common.sayHello("MINA")
                    },
                    goodbyeMINA:function(){
                        common.sayGoodbye("MINA")
                    }
                })

    module

        当前模块对象

    属性
    属性 类型 说明
    exports Object 模块向外暴露的对象,使用require引用该模块时可以获取

    示例代码:
                // common.js
                function sayHello(name){
                    console.log(`hello ${name}`)
                }
                function sayGoodbye(name){
                    console.log(`goodbye ${name}`)
                }
    
                module.exports.sayHello=sayHello
                exports.sayGoodbye=sayGoodbye

    exports

        module.exports的引用

    示例代码:
                // common.js
                function sayHello(name){
                    console.log(`hello ${name}`)
                }
                function sayGoodbye(name){
                    console.log(`goodbye ${name}`)
                }
    
                module.exports.sayHello=sayHello
                exports.sayGoodbye=sayGoodbye

    导出:

      module.exports={};

    引入:

      const util=require("../../utils/util");

  • 相关阅读:
    [POI2005]A Journey to Mars 单调队列
    滑动窗口 单调队列
    逆序对 模拟贪心
    迷宫 dfs爆搜
    [Usaco2019 Feb]The Great Revegetation
    [Usaco2007 Dec]挑剔的美食家
    [HNOI2004]宠物收养所
    bzoj2639 矩形计算
    [Ahoi2013]作业
    Gty的二逼妹子序列
  • 原文地址:https://www.cnblogs.com/wuqilang/p/12076131.html
Copyright © 2011-2022 走看看