微信小程序module.exports模块化操作实例浅析

时间:2021-05-18

本文实例讲述了微信小程序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 }); }})

index.wxml:

<block wx:for="{{studentList}}" wx:for-item="item" wx:for-index="idx"> <view> {{item.name}} </view></block>

因为取的是name,所以最后输出的是xiaoming 和xiaohong。如下图所示(这里就懒得弄样式了~):

希望本文所述对大家微信小程序开发有所帮助。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章