新闻详情

新闻详情

首页 / 资讯中心 / 详情

微信小程序【模块化】

发布时间:2026/11/4 20:16:03来源:尧图网络
微信小程序【模块化】
一、完成效果二、制作流程1.在小程序根目录下新建一个common文件夹在该文件夹下新建common.js文件.// common.js const comMsg 来自不同目录下模块的变量 function comFunc() { return 来自不同目录下模块的函数 } // 导出模块的变量和函数 module.exports { comMsg, comFunc }2.在index文件夹下新增模块文件my-index.js// my-index.js const myIndexMsg 来自相同目录下不同模块的变量 function myIndexFunc() { return 来自相同目录下不同模块的函数 } module.exports { myIndexMsg, myIndexFunc }3.修改app.js文件// app.js App({ appMsg: 来自全局模块的变量, appFunc() { return 来自全局模块的函数 } })4.修改index.js文件// index.js const indexMsg 来自本模块的变量 function indexFunc() { return 来自本模块的函数 } // 获取到小程序全局唯一的 App 实例。 const app getApp() // 引入模块common。返回common模块通过 module.exports 或 exports 暴露的接口 const comm require(../../common/common.js) // 引入模块my-index。返回my-index模块通过 module.exports 或 exports 暴露的接口 const myIndex require(my-index.js) Page({ data: { // 使用app.js文件中的变量和函数 msg1: index.js模块引用 app.appMsg, msg2: index.js模块引用 app.appFunc(), // 使用common.js文件中的变量和函数 msg3: index.js模块引用 comm.comMsg, msg4: index.js模块引用 comm.comFunc(), // 使用my-index.js文件中的变量和函数 msg5: index.js模块引用 myIndex.myIndexMsg, msg6: index.js模块引用 myIndex.myIndexFunc(), // 使用本模块的变量和函数 msg7: index.js模块引用 indexMsg, msg8: index.js模块引用 indexFunc() } })5.修改index.wxml文件!--index.wxml-- navigation-bar title模块化 back{{false}} colorblack background#FFF/navigation-bar scroll-view classscrollarea scroll-y typelist view classbox view classtitle引用来自不同模块的变量和函数/view !-- app.js 全局模块 -- view classbg-blue{{msg1}}/view view classbg-blue{{msg2}}/view !-- common.js 不同目录模块 -- view classbg-yellow{{msg3}}/view view classbg-yellow{{msg4}}/view !-- my-index.js 相同目录模块 -- view classbg-purple{{msg5}}/view view classbg-purple{{msg6}}/view !-- index.js 本模块 -- view classbg-green{{msg7}}/view view classbg-green{{msg8}}/view /view /scroll-view6.修改index.wxss文件/**index.wxss**/ page { height: 100vh; display: flex; flex-direction: column; } .scrollarea { flex: 1; overflow-y: hidden; } view { line-height: 2em; font-size: 40rpx; } /* --- 以下为新增的纯背景颜色柔和护眼 --- */ /* 1. 全局模块淡蓝色 */ .bg-blue { background-color: #e6f4ff; } /* 2. 不同目录模块淡黄色 */ .bg-yellow { background-color: #fffbe6; } /* 3. 相同目录模块淡紫色 */ .bg-purple { background-color: #f9f0ff; } /* 4. 本模块淡绿色 */ .bg-green { background-color: #f6ffed; }7.修改app.wxss文件/**app.wxss**/ .container { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 200rpx 0; box-sizing: border-box; } /**app.wxss**/ .box { /* 设置外边距 */ margin: 20rpx; /* 设置内边距 */ padding: 20rpx; /* 设置边框 */ border: 2rpx solid silver; } .title { /* 设置字体大小 */ font-size: 40rpx; /* 设置字体加粗 */ font-weight: bolder; /* 设置居中对齐 */ text-align: center; /* 设置下外边框 */ margin-bottom: 30rpx; /* 设置字体颜色 */ color: red; }三、知识要点四、个人总结希望可以坚持学下去
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

【外设】之大彩串口显示屏 2026/11/4 15:56:54

【外设】之大彩串口显示屏

大彩串口屏初步使用 1 .官网下载 STM32 屏幕 GUI 设计资料 http://www.gz-dc.com/category/typeid/4112 找到 STM32 Keil 工程,移植相关代码因项目而异进行移植,由于项目简单,本人只对用到的指令接口进行修改。 比如:注意事项&…

阅读更多 →
无法下载Windows系统iso文件 2026/11/3 12:09:35

无法下载Windows系统iso文件

当我遇到这个问题的时候,我打开了一个网站: 登录 然后我打算下载的时候: 突然那个官方的连接就可以下载了:

阅读更多 →
【清华代码熊】DeepSeek V4.1 Flash 后训练详解 2026/11/4 17:01:23

【清华代码熊】DeepSeek V4.1 Flash 后训练详解

📌 上期解析了 DeepSeek V4.1 Flash 模型架构改进,本期解析 DeepSeek V4.1 Flash 预训练/后训练技术: 🌟 预训练:45T 文本 多模态混合语料、直接训练 sparse attention(取消 DeepSeek V4 的 dense 冷启动&…

阅读更多 →
Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ... 2026/11/4 12:33:12

Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ...

文章主要内容和创新点 主要内容 本文聚焦于多模态大语言模型(MLLM)强化学习(RL)训练中的效率问题,提出了一个名为Shuffle-R1的框架。研究发现,当前RL训练存在两个关键缺陷: 优势值坍缩(Advantage Collapsing):批次中大多数优势值集中在零附近,导致有效梯度信号被淹…

阅读更多 →
PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction 2026/11/4 1:25:31

PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction

一、文章主要内容总结 本文聚焦于利用大型语言模型(LLMs)实现个人身份信息(PII)脱敏的研究,旨在解决传统脱敏方法(如基于规则的系统、领域特定命名实体识别(NER)模型)泛化能力差、跨格式/跨语境适应性弱的问题。 研究通过全面评估多种LLM架构(包括密集型LLM(D-LLM…

阅读更多 →
LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model 2026/11/4 3:51:11

LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model

文章主要内容和创新点 主要内容 本文聚焦于二进制图像-文本相关性评估任务(判断图像与文本“相关”或“不相关”),针对该任务中文本格式多样、相关性定义随场景变化等挑战,提出了基于多模态大语言模型(MLLM)的解决方案LLaVA-RE。 模型设计:LLaVA-RE基于LLaVA 1.5架构,…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉