//common.jshtml
var studentList = [
app
{
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
});
}
})
由於取的是name,因此最後輸出的是xiaoming 和xiaohong。模塊化