一、 系统常用api
1. wx.openAppAuthorizeSetting(Object object) 跳转系统微信授权管理页
1. wx.openAppAuthorizeSetting(Object object) Skip to system WeChat authorization management page
2. wx.getWindowInfo() 获取窗口信息
2. wx.getWindowInfo() Get Window Info
3.wx.getSystemInfoSync() ; wx.getSystemInfo 的同步版本
3. wx.getSystemInfoAsync(Object object) 异步获取系统信息。需要一定的微信客户端版本支持,在不支持的客户端上,会使用同步实现来返回。
3. wx. getSystemInfoAsync (Object object) Gets system information asynchronously. It needs to be supported by certain WeChat client version. On the unsupported client, it will be returned by synchronization.
4. wx.getAppAuthorizeSetting() 获取微信 APP 授权设置
4. wx.getAppAuthorizeSetting() to obtain WeChat APP authorization settings
二、小程序常用api
II. Common api of Mini programs
小程序常用生命周期
Mini programs Common Life Cycle
1.wx.getLaunchOptionsSync 获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。
1. wx.getLaunchOptionsSync Get the parameters when the Mini programs starts. Consistent with App.onLaunch callback parameters.
2.wx.getEnterOptionsSync 获取本次小程序启动时的参数。如果当前是冷启动,则返回值与 App.onLaunch 的回调参数一致;如果当前是热启动,则返回值与 App.onShow 一致。
2. wx.getEnterOptionsSync obtains the parameters when the Mini programs is started. If it is a cold start, the return value is consistent with the callback parameter of App. onLaunch;If the current is a warm boot, the return value is the same as App. onShow.
3.wx.onUnhandledRejection(function listener) 监听未处理的 Promise 拒绝事件。该事件与 App.onUnhandledRejection 的回调时机与参数一致。
3. wx. onUnhandledRejection (function listener) listens for unhandled Promise rejection events. This event matches the timing and parameters of the callback for App. onUnhandledRejection.
4.wx.onThemeChange(function listener) 监听系统主题改变事件。该事件与 App.onThemeChange 的回调时机一致。
4. wx. onThemeChange (function listener) listens for system theme change events. This event coincides with the timing of the App.onThemeChange callback.
5.wx.onPageNotFound(function listener) 监听小程序要打开的页面不存在事件。该事件与 App.onPageNotFound 的回调时机一致。
5. wx. onPageNotFound (function listener) listens for the event that the page to be opened by the Mini programs does not exist. This event coincides with the callback timing of App. onPageNotFound.
6.wx.onLazyLoadError(function listener) 监听小程序异步组件加载失败事件。
6. wx. onLazyLoadError (function listener) Listens for Mini programs asynchronous component loading failure events.
7.wx.onError(function listener) 监听小程序错误事件。如脚本错误或 API 调用报错等。该事件与 App.onError 的回调时机与参数一致。
7. wx. onError (function listener) listens for Mini programs error events. such as a script error or an API call error. This event is consistent with the timing and parameters of the App.onError callback.
8.wx.onAudioInterruptionEnd(function listener) 监听音频中断结束事件。在收到 onAudioInterruptionBegin 事件之后,小程序内所有音频会暂停,收到此事件之后才可再次播放成功
8. wx. onAudioInterruptionEnd (function listener) Listen for audio interrupt end event. After receiving the onAudioInterruptionBegin event, all audio in the Mini programs will be paused. Only after receiving this event can it be played successfully again
9.wx.onAppShow(function listener) 监听小程序切前台事件。该事件与 App.onShow 的回调参数一致。
9. wx. onAppShow (function listener) listens for Mini programs foreground switching events. This event is consistent with the callback parameters of App.onShow.
10.wx.onAppHide(function listener) 监听小程序切后台事件。该事件与 App.onHide 的回调时机一致。
10.wx.onAppHide(function listener) listens for Mini programs switching background events. This event coincides with the timing of the App.onHide callback.
三、路由跳转api
III. Routing jump api
1.wx.switchTab(Object object) 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
1. wx. switchTab (Object object) Jump to the tabBar page and close all other non-tabBar pages
2.wx.reLaunch(Object object) 关闭所有页面,打开到应用内的某个页面
2.wx.reLaunch(Object object) Closes all pages and opens to a page within the application
3.wx.redirectTo(Object object) 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
3. wx. redirectTo (Object object) Closes the current page and jumps to a page within the application. However, jumping to the tabbar page is not allowed.
4.wx.navigateTo(Object object) 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 wx.navigateBack 可以返回到原页面。小程序中页面栈最多十层。
5.wx.navigateBack(Object object) 关闭当前页面,返回上一页面或多级页面。可通过 6.getCurrentPages 获取当前的页面栈,决定需要返回几层。
7.wx.exitMiniProgram(Object object) 退出当前小程序。必须有点击行为才能调用成功。
四、转发api
1.wx.updateShareMenu(Object object) 更新转发属性
2.wx.showShareMenu(Object object) 显示当前页面的转发按钮
3.wx.showShareImageMenu(Object object) 打开分享图片弹窗,可以将图片发送给朋友、收藏或下载
4.wx.shareVideoMessage(Object object) 转发视频到聊天
5.wx.shareFileMessage(Object object) 转发文件到聊天
五、页面交互
1.wx.showToast(Object object) 显示消息提示框
2.wx.showModal(Object object) 显示模态对话框
3.wx.showLoading(Object object) 显示 loading 提示框。需主动调用
4.wx.hideLoading 才能关闭提示框
5.wx.showActionSheet(Object object) 显示操作菜单
6.wx.hideToast(Object object) 隐藏消息提示框
7.wx.hideLoading(Object object) 隐藏 loading 提示框
8.wx.enableAlertBeforeUnload(Object object) 开启小程序页面返回询问对话框。
9.wx.disableAlertBeforeUnload(Object object) 关闭小程序页面返回询问对话框。