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

      可以将一些公共的代码抽离成为一个单独的 js 文件,作为一个模块。模块只有通过 module.exports 或者 exports 才能对外暴露接口。

      需要注意的是:

    • exportsmodule.exports 的一个引用,因此在模块里边随意更改 exports 的指向会造成未知的错误。所以更推荐开发者采用 module.exports 来暴露模块接口,除非你已经清晰知道这两者的关系。
    module.exports = {
        postList: local_database
    }

      在需要使用这些模块的文件中,使用 require(path) 将公共代码引入(只能用相对路径).

    var postsData = require('../../data/posts-data.js')
    onLoad: function () {
        this.data.postList = postsData.postList
    }
    

      

  • 相关阅读:
    OpenCV之设计模式
    ca
    BMP结构详解
    Lucas–Kanade光流算法学习
    卡尔曼
    hash+链表
    文件操作
    查找
    fseek效率
    大家都说3C直连网络,3C网络是指什么呢?
  • 原文地址:https://www.cnblogs.com/superlizhao/p/8330146.html
Copyright © 2011-2022 走看看