小程序定義公共函數


格式如下:

 

引用使用:

微信小程序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

歡迎關注,有問題一起學習歡迎留言、評論。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM