# 基础 ## 💡 核心结论 1. **小程序采用双线程架构:逻辑层(JSCore)和视图层(WebView)分离** 2. **WXML是类HTML语法,WXSS是类CSS语法,支持rpx响应式单位** 3. **生命周期分为应用生命周期和页面生命周期** 4. **小程序不支持DOM操作,数据驱动视图更新** 5. **小程序包体积限制2MB,分包后主包不超过2MB** --- ## 1. 快速开始 ### 1.1 注册与配置 ```bash # 1. 注册小程序账号 https://mp.weixin.qq.com/ # 2. 获取AppID 开发 → 开发管理 → 开发设置 → AppID # 3. 下载开发者工具 https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html ``` ### 1.2 项目结构 ``` my-miniprogram/ ├── pages/ # 页面目录 │ ├── index/ │ │ ├── index.js # 页面逻辑 │ │ ├── index.json # 页面配置 │ │ ├── index.wxml # 页面结构 │ │ └── index.wxss # 页面样式 │ └── logs/ │ ├── logs.js │ ├── logs.json │ ├── logs.wxml │ └── logs.wxss ├── utils/ # 工具函数 │ └── util.js ├── app.js # 应用逻辑 ├── app.json # 全局配置 ├── app.wxss # 全局样式 ├── project.config.json # 项目配置 └── sitemap.json # 索引配置 ``` ### 1.3 全局配置 (app.json) ```json { "pages": [ "pages/index/index", "pages/logs/logs" ], "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "我的小程序", "navigationBarTextStyle": "black", "enablePullDownRefresh": true, "backgroundColor": "#f8f8f8" }, "tabBar": { "color": "#999", "selectedColor": "#07c160", "backgroundColor": "#fff", "borderStyle": "black", "list": [ { "pagePath": "pages/index/index", "text": "首页", "iconPath": "images/home.png", "selectedIconPath": "images/home-active.png" }, { "pagePath": "pages/profile/profile", "text": "我的", "iconPath": "images/profile.png", "selectedIconPath": "images/profile-active.png" } ] }, "networkTimeout": { "request": 10000, "downloadFile": 10000 }, "debug": false } ``` --- ## 2. 页面开发 ### 2.1 WXML 语法 **数据绑定**: ```html {{message}} {{a + b}} {{flag ? '真' : '假'}} Item {{index + 1}} ``` **列表渲染**: ```html {{index}}: {{item.name}} {{idx}}: {{product.name}} {{item.name}} {{product.name}} ``` **条件渲染**: ```html 显示内容 其他内容 默认内容 内容1 内容2 ``` **模板**: ```html