微信小程序module.exports模块化操作实例浅析
作者:CoKeny 时间:2023-07-02 05:30:27
本文实例讲述了微信小程序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。如下图所示(这里就懒得弄样式了~):
希望本文所述对大家微信小程序开发有所帮助。
来源:https://www.cnblogs.com/panlaixing/p/6736499.html
标签:微信小程序,module.exports,模块化
0
投稿
猜你喜欢
Python对两个有序列表进行合并和排序的例子
2022-06-07 00:11:37
详细介绍Python中的set集合
2023-07-26 07:35:03
关于Javascript的内存泄漏问题
2008-04-15 07:46:00
python3 wechatpy微信支付的项目实践
2023-08-29 14:13:36
Python的子线程和子进程是如何手动结束的?
2022-09-08 18:54:41
再谈“字符串拼接”的效率
2009-04-30 12:48:00
oracle用什么SQL语句判断表存不存在
2010-07-23 13:23:00
20招让你的Python飞起来!
2022-08-24 18:39:39
如何优化SQL语句(全)
2024-01-27 06:12:59
终于搞懂了Python中super(XXXX, self).__init__()的作用了
2022-01-04 00:35:44
numpy中loadtxt 的用法详解
2022-03-21 09:46:39
Python MySQLdb 使用utf-8 编码插入中文数据问题
2023-07-31 11:04:13
在Python中操作列表之List.pop()方法的使用
2021-06-20 12:02:17
django实现模型字段动态choice的操作
2023-08-13 07:30:31
python数据结构leetcode338比特位计数算法
2023-05-06 21:24:33
SQL常用的四个排序函数梳理
2024-01-13 04:41:49
Django学习之静态文件与模板详解
2022-12-13 13:19:58
php floor()函数案例详解
2023-06-14 16:13:03
解析SQL2005中如何使用CLR函数获取行号
2024-01-12 14:18:35
pytorch中的hook机制register_forward_hook
2022-03-24 10:37:12