官方API使用
首先需要找到想要使用的API文档。在基础文档里位置如下。找到之后,查看文档中关于此接口的说明,查看使用方法和使用案例后即可使用。
![](https://img-blog.csdnimg.cn/img_convert/3f186868baf1ac95fbd660bd2224640c.png)
路由跳转模块
在使用页面路由之前,需要先导入router模块
![](https://img-blog.csdnimg.cn/img_convert/695ed2dae17d0c596db997078c67be70.png)
页面跳转的几种方式
![](https://img-blog.csdnimg.cn/img_convert/cf53a1117b5b2bfa09030a3f3a222e8f.png)
![](https://img-blog.csdnimg.cn/img_convert/9cdb79fb1f3c8314d344aabc1f10121c.png)
![](https://img-blog.csdnimg.cn/img_convert/76687e2782ff394c982e60535dd12c1d.png)
![](https://img-blog.csdnimg.cn/img_convert/bf432309563b6a092c2adcd9b8f04803.png)
通过调用router.getParams()方法获取Index页面传递过来的自定义参数。
![](https://img-blog.csdnimg.cn/img_convert/b846fc36d44f43be96bbb3c00871228f.png)
在Second页面中,可以通过调用router.back()方法实现返回到上一个页面,或者在调用router.back()方法的时增加可选的options参数(增加url参数)返回到指定页面。
![](https://img-blog.csdnimg.cn/img_convert/47e8a53ba94dfc7a2c258122fccddbe2.png)
![](https://img-blog.csdnimg.cn/img_convert/a7a3c705b6cea11ba3cdb5061e203be0.png)
数据请求模块
导入模块
![](https://img-blog.csdnimg.cn/img_convert/6084278da6952279818c742950dd9447.png)
配置权限
在config.json的module模块里配置,示例如下。
配置网络权限
![](https://img-blog.csdnimg.cn/img_convert/988b5c2b1d4d8674ad8de8a28babc62e.png)
完整事例
![](https://img-blog.csdnimg.cn/img_convert/50d9342671a49801b564b357dda7e33c.png)
弹窗模块
首先需要导入prompt模块
![](https://img-blog.csdnimg.cn/img_convert/af04443b254ade350f0d1e121eaf21d6.png)
主要使用的是prompt.showToast()方法,作用是可以在屏幕上弹出提示信息。message是弹出的消息,而duration是弹出的时间,单位是毫秒。1000是1秒,则2000是2秒。
![](https://img-blog.csdnimg.cn/img_convert/1d7972b5eae98e78b7bda9173d7b75b6.png)
绑定事件
用on加事件名称,不同的组件有不同的事件类型。通用事件如下:
点击事件
![](https://img-blog.csdnimg.cn/img_convert/604e6b47bfa09a4ec080cbd0245ee5fb.png)
触摸事件
![](https://img-blog.csdnimg.cn/img_convert/756a987e1a6d768d7eb5669d61fc290c.png)
挂载卸载事件
![](https://img-blog.csdnimg.cn/img_convert/2616a4f7ee2a31d8c35e1e5a85f1822a.png)
拖拽事件
![](https://img-blog.csdnimg.cn/img_convert/d12c7ba7df06defdee1ea56c7f76b1fe.png)