小程序定义公共函数

格式如下:

 

引用使用:

微信小程序module.exports 模块化

/common.js

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

var studentList = [

    {

        name: "xiaoming",

        age: "22",

        hobby: "sleep"

    },

    {

        name: "xiaohong",

        age: "22",

        hobby: {

            one: "eat",

            two: "eatfood"

        }

   

    }

]

   

//模块化

module.exports = {

    studentList: studentList

}

   

1

2

3

4

5

6

7

8

9

10

11

12

13

14

//index.js

var common = require("../aa/common.js")

//获取应用实例

var app = getApp()

Page({

  data: {

  },

     

  onLoad: function () {

    this.setData({

        studentList:common.studentList

        });

  }

})

 

 

文章来源:刘俊涛的博客

地址:http://www.cnblogs.com/lovebing

欢迎关注,有问题一起学习欢迎留言、评论。

posted @ 2018-04-13 17:21  刘俊涛的博客  阅读(4362)  评论(0)    收藏  举报