赞
踩
运行环境
是微信,全程使用微信服务├── pages # 存放小程序的各个页面 │ ├── index # index页面 │ │ ├── index.js # 页面逻辑 │ │ ├── index.json # 页面配置 │ │ ├── index.wxml # 页面结构 │ │ └── index.wxss # 页面样式表 │ └── logs # logs页面 │ ├── logs.js # 页面逻辑 │ ├── logs.json # 页面配置 │ ├── logs.wxml # 页面结构 │ └── logs.wxss # 页面样式表 ├── utils │ └── util.js ├── app.js # 小程序的逻辑文件 ├── app.json # 小程序的配置文件 ├── app.wxss # 全局公共样式文件 └── project.config.json # 全局项目配置
小程序标签 | 含义 |
---|---|
view | div |
text | span |
image | img |
picker | select |
navigator | a |
button | button |
block | 包裹容器,不渲染 |
swiper | 滑块视图容器 |
map | 腾讯地图 |
icon | 微信图标 |
progress | 进度条 |
wxs | 过滤器,类似 js |
类型 | 语法 |
---|---|
内容 | {{ 变量名 }} |
属性 | 属性=“{{ 变量名 }}” |
运算 | 三元 / 算数表达式 |
类型 | 语法 |
---|---|
tap | bindtap / bind:tap |
input | bindinput / bind:input |
change | bindchange / bind:change |
类型 | 语法 |
---|---|
处理 data 数据 | this.setData(dataObject) |
事件传参 | data-参数名=“{{ 参数 }}” |
事件取参 | e.target.dataset.参数名 |
input 取值 | e.detail.value |
data-input 数据同步 | data 定义数据变量 => 动态绑定 value => this.setData(数据变量:e.detail.value) |
wx:if = "{{ }}"
wx:elif = "{{ }}"
wx:else
hidden = "{{ }}"
wx:for = "{{ Array }}" // 循环数组
{{ index }} // 默认索引
{{ item }} // 默认循环项
wx:for-index = "{{ newindex }}" // 索引重命名
wx:for-item = "{{ newitem }}" // 循环项重命名
{{ newindex }} // 重命名索引
{{ newitem }} // 重命名循环项
wx:key = "id"
@import “相对路径”
类型 | 含义 |
---|---|
pages | 记录当前小程序所有页面的存放路径 |
window | 全局设置小程序窗口的外观 |
tabBar | 设置小程序底部的 tabBar 效果 |
style | 是否启用新版的组件样式 |
属性 | 类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
list | Array | 是 | tab 列表,详见 list 属性说明 | tab 范围 2-5 |
color | HexColor | 否 | tab 文字默认色 | 仅支持十六进制 |
selectedColor | HexColor | 否 | tab 文字选中色 | 仅支持十六进制 |
backgroundColor | HexColor | 否 | tab 背景色 | 仅支持十六进制 |
borderStyle | string | 否 | black | tabbar 上边框的颜色,仅支持 black / white |
position | string | 否 | bottom | tabBar 位置,仅支持 bottom / top (top 时无 icon) |
custom | boolean | 否 | false | 自定义 tabBar |
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
pagePath | string | 是 | 页面路径,必须在 pages 中先定义 |
text | string | 是 | tab 按钮文字 |
iconPath | string | 否 | position 为 top 时,不显示 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片 |
selectedIconPath | string | 否 | position 为 top 时,不显示 选中时图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,不支持网络图片 |
网络数据请求
wx:request()
HTTPS
类型接口信任列表
登录微信小程序管理后台
=> 开发
=> 开发设置
=> 服务器域名
=> 修改 request 合法域名
getInfo(){
wx.request({
url:"https://domain’, // 请求的接口地址,必须基于 https 协议
method :GET, // 请求的方式
data: { // 发送到服务器的数据
name : ' zs',
age: 22
},
success: (res) => { // 请求成功之后的回调函数
console.log(res)
}
})
}
postInfo(){
wx.request({
url:"https://domain’, // 请求的接口地址,必须基于 https 协议
method :POST, // 请求的方式
data: { // 发送到服务器的数据
name : ' zs',
age: 22
},
success: (res) => { // 请求成功之后的回调函数
console.log(res)
}
})
}
onLoad:function(){
this.getInfo()
this.postInfo()
}
开发环境不校验请求域名、TLS 版本及 HTTPS 证书
选项,跳过request 合法域名校验<navigator>
导航组件(类似 a 标签)属性 | 说明 | 必填 | 默认值 |
---|---|---|---|
topen-type=‘switchTab’ | 跳转 tabBar 页面 | 是 | |
topen-type=‘navigate’ | 跳转非 tabBar 页面 | 否 | 跳转非 tabBar 页面 |
topen-type=‘navigateBack’ delta=‘n’ | 后退导航 后退层级 | 是 否 | delta = ‘1’ |
// 跳转 tabBar 页面
<navigator url='/pages/home/home' topen-type='switchTab'>导航到 tabBar 页面<navigator/>
// 跳转非 tabBar 页面
<navigator url='/pages/info/info' topen-type='navigate'>导航到非 tabBar 页面<navigator/>
<navigator url='/pages/info/info'>导航到非 tabBar 页面<navigator/>
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
url | string | 是 | 需要跳转的 tabBar 页面路径,不能带参数 |
success | function | 是 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数 |
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
url | string | 是 | 需要跳转的非 tabBar 页面路径 |
success | function | 是 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数 |
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
delta | number | 是 | 返回的页面数,默认 delta = 1 若大于现有页面数,返回首页 |
success | function | 是 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数 |
// .wxml <button bindtap="toDreams">导航到 tabBar</button> <button bindtap="toData">导航到非 tabBar</button> <button bindtap="backOne">编程式导航后退 1 层</button> <button bindtap="backN">编程式导航后退 N 层</button> // .js // 编程式导航到 tabBar toDreams(){ wx.switchTab({ url: '/pages/dreams/dreams', }) }, // 编程式导航到非 tabBar toData(){ wx.navigateTo({ url: '/pages/info/info', }) }, // 编程式导航后退 1 层 backOne(){ wx.navigateBack() }, // 编程式导航后退 N 层 backN(){ wx.navigateBack({ delta: 5 }) },
<navigator url='/pages/info/info?name=zs&age=11'>导航到 info 页面<navigator/>
// .wxml
<button bindtap="toData">导航到 info 页面</button>
// .js
// 编程式导航到非 tabBar
toData(){
wx.navigateTo({
url: '/pages/info/info?name=zs&age=11',
})
}
// options 为导航传递过来的参数对象
onLoad(options){
this.setData({
query: toptions
)}
}
页面单独开启
"enablePullDownRefresh ": true, // 开启下拉刷新
"backgroundColor": "#efefef", // 修改下拉刷新背景色
"backgroundTextStyle": "dark" // 修改下拉刷新圆点色(dark/light)
"onReachBottomDistance":100 // 默认值为 50,默认为 px 单位无需手动添加
app.js
中声明应用生命周期函数App({
onLaunch(options) { }, // 小程序初始化完成时,全局触发一次(初始化数据)
onShow(options) { }, // 小程序启动,或从后台进入前台显示时触发
onHide() { } // 小程序从前台进入后台时触发
)}
页面.js
中声明页面生命周期函数Page({
onLoad(options){ }, // 监听页面加载,一个页面只调用一次(初始化数据)
onShow() { }, // 监听页面显示
onReady() { }, // 监听页面初次渲染完成,一个页面只调用一次(修改页面内容)
onHide() { }, // 监听页面隐藏
onUnload() { } // 监听页面卸载,一个页面只调用一次
)}
// .json
"usingComponents":{
"组件名": "组件路径"
}
// .wxml
<组件名></组件名>
使用 class 选择器
,不使用 id / 属性 / 标签选择器stylelsolation
修改组件的样式隔离选项,以下两种方法均可// 在组件的 js 文件中新增如下配置
Component({
options: {
styleIsolation: "isolated'
}
})
// 在组件的 .json 文件中新增如下配置
"styleIsolation":"isolated"
stylelsolation | 默认值 | 描述 |
---|---|---|
isolated | 是 | 启用样式隔离,在自定义组件内外,使用 class 指定的样式不会相互影响 |
apply-shared | 否 | 页面 wxss 样式影响自定义组件,但自定义组件 wxss 样式不影响页面 |
shared | 否 | 页面 wxss 样式影响自定义组件,自定义组件 wxss 样式也影响页面 和其他设置 apply-shared 或 shared 的自定义组件 |
事件处理函数
和自定义方法
定义到 methods 节点_
开头properties
,用来接收外界传递到组件中的数据Component({
// 属性定义
properties: {
max: { // 1、完整定义属性的方式【需要默认值】
type: Number, // 属性值的数据类型
value: 10 // 属性默认值
},
max: Number // 2、简化定义属性的方式【不用默认值】
}
})
<my-test1 max="10"></my-test1>
Node.js 内置库
、浏览器内置对象
、C++ 插件
的包// 通过 npm 安装
npm i vant-weapp -S --production
// 通过 yarn 安装
yarn add vant-weapp --production
使用 npm 模块
选项
// app.json
"usingComponents": {
"van-button": "../../miniprogram_npm/vant-weapp/button/index" // 本地相对路径
}
// .wxml
<van-button type="primary">按钮</van-button>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。