微信小程序module.exports 模块化

//common.js

var studentList = [

    {
        name: "xiaoming",
        age: "22",
        hobby: "sleep"
    },
    {
        name: "xiaohong",
        age: "22",
        hobby: {
            one: "eat",
            two: "eatfood"
        }
 
    }
]
 
//模块化
module.exports = {
    studentList: studentList
}
 
 
 
//index.js
var common = require("../aa/common.js")
//获取应用实例
var app = getApp()
Page({
  data: {
  },
   
  onLoad: function () {
    this.setData({
        studentList:common.studentList
        });
  }
})
 
 
 
微信小程序module.exports 模块化

 

因为取的是name,所以最后输出的是xiaoming    和xiaohong。

 

相关文章:

  • 2021-12-05
  • 2022-02-18
  • 2021-08-25
  • 2021-10-25
  • 2021-08-10
  • 2022-12-23
  • 2021-06-18
  • 2021-05-26
猜你喜欢
  • 2021-08-29
  • 2021-11-19
  • 2021-12-26
  • 2021-12-20
  • 2021-11-19
  • 2021-04-10
  • 2021-05-26
相关资源
相似解决方案