1、写个自定义方法,携带参数

事件对象可以携带额外信息,通过使用data- 自定义传值
方法使用evt.target.dataset.获取传的值

  1. data: {
  2. sum: 0
  3. },
  4. // 自定义方法
  5. total(evt) {
  6. this.setData({
  7. sum: evt.target.dataset.a*1 + evt.target.dataset.b*1
  8. })
  9. console.log(this.data.sum);
  10. },
  1. <view bindtap="total" data-a="4" data-b="5">4 + 5 = {{sum}}</view>

2、列出20个小程序api,写出功能。

名称功能说明
wx.onAppShow监听小程序切前台事件
wx.onAppHide监听小程序切后台事件
wx.offAppShow取消监听小程序切前台事件
wx.offAppHide取消监听小程序切后台事件
wx.switchTab跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
wx.reLaunch关闭所有页面,打开到应用内的某个页面
wx.redirectTo关闭当前页面,跳转到应用内的某个页面
wx.navigateTo保留当前页面,跳转到应用内的某个页面
wx.navigateBack关闭当前页面,返回上一页面或多级页面
wx.showToast显示消息提示框
wx.showModal显示模态对话框
wx.showLoading显示 loading 提示框
wx.showActionSheet显示操作菜单
wx.hideToast隐藏消息提示框
wx.hideLoading隐藏 loading 提示框
wx.setStorageSyncwx.setStorage 的同步版本
wx.setStorage将数据存储在本地缓存中指定的 key 中
wx.removeStorageSyncwx.removeStorage 的同步版本
wx.removeStorage从本地缓存中移除指定 key
wx.getStorageSyncwx.getStorage 的同步版本
wx.getStorageInfoSyncwx.getStorageInfo 的同步版本
wx.getStorageInfo异步获取当前storage的相关信息
wx.getStorage从本地缓存中异步获取指定 key 的内容
wx.clearStorageSyncwx.clearStorage 的同步版本
wx.clearStorage清理本地数据缓存
wx.request发起 HTTPS 网络请求
wx.uploadFile将本地资源上传到服务器
wx.downloadFile下载文件资源到本地

3、生成10个页面,用navigator组件进行跳转。

  • navigator 页面链接
编号属性类型默认值必填说明
1targetstringself在哪个目标上发生跳转,默认当前小程序
1urlstring当前小程序内的跳转链接
2open-type stringnavigate跳转方式
3deltanumber 1当 open-type 为 ‘navigateBack’ 时有效,表示回退的层数
4app-idstring当 target=”miniProgram”时有效,要打开的小程序
5pathstring当 target=”miniProgram”时有效,打开的页面路径,如果为空则打开首页
6extra-dataobject当 target=”miniProgram”时有效,需要传递给目标小程序的数据,目标小程序可在 App.onLaunch(),App.onShow() 中获取到这份数据。
7versionstring release当 target=”miniProgram”时有效,要打开的小程序版本
8hover-classstring navigator-hover指定点击时的样式类,当 hover-class=”none”时,没有点击态效果
9hover-stop-propagationbooleanfalse 否指定是否阻止本节点的祖先节点出现点击态
10hover-start-timenumber 50按住后多久出现点击态,单位毫秒
11hover-stay-timenumber 600手指松开后点击态保留时间,单位毫秒
12bindsuccessstring当 target=”miniProgram”时有效,跳转小程序成功
13bindfailstring当 target=”miniProgram”时有效,跳转小程序失败
14bindcompletestring当 target=”miniProgram”时有效,跳转小程序完成
  • target 的合法值
编号说明
1self当前小程序
2miniProgram其它小程序
  • open-type 的合法值
编号说明
1switchTab跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
2reLaunch关闭所有页面,打开到应用内的某个页面
3redirect关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面
4navigate保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面
5navigateBack关闭当前页面,返回上一页面或多级页面
6exit退出小程序,target=”miniProgram”时生效

app.json

  1. {
  2. "pages":[
  3. "pages/5/5",
  4. "pages/4/4",
  5. "pages/3/3",
  6. "pages/2/2",
  7. "pages/1/1",
  8. "pages/index/index",
  9. "pages/ad/ad",
  10. "pages/art/art",
  11. "pages/admin/admin",
  12. "pages/logs/logs"
  13. ],
  14. "style": "v2",
  15. "sitemapLocation": "sitemap.json",
  16. "window": {
  17. "navigationBarBackgroundColor": "#ffffff",
  18. "navigationBarTextStyle": "black",
  19. "navigationBarTitleText": "默默记账",
  20. "backgroundColor": "#eeeeee",
  21. "backgroundTextStyle": "light",
  22. "enablePullDownRefresh": false
  23. },
  24. "tabBar": {
  25. "color": "#444444",
  26. "selectedColor": "red",
  27. "backgroundColor": "#ffffff",
  28. "position": "bottom",
  29. "borderStyle": "black",
  30. "list": [{
  31. "pagePath": "pages/index/index",
  32. "text": "主页",
  33. "iconPath": "./static/img/1.png",
  34. "selectedIconPath": "./static/img/2.png"
  35. },
  36. {"pagePath": "pages/ad/ad",
  37. "text": "广告",
  38. "iconPath": "./static/img/1.png",
  39. "selectedIconPath": "./static/img/2.png"
  40. },
  41. {"pagePath": "pages/art/art",
  42. "text": "文章",
  43. "iconPath": "./static/img/3.png",
  44. "selectedIconPath": "./static/img/4.png"
  45. },
  46. {
  47. "pagePath": "pages/logs/logs",
  48. "text": "日志",
  49. "iconPath": "./static/img/3.png",
  50. "selectedIconPath": "./static/img/4.png"
  51. }
  52. ]
  53. }
  54. }
  1. <text>pages/5/5.wxml</text>
  2. <navigator url="/pages/4/4">保留当前页面,跳转到4页面。但是不能跳到 tabbar 页面</navigator>
  3. <navigator url="/pages/logs/logs" open-type="switchTab">跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面</navigator>
  4. <navigator url="/pages/2/2" open-type="reLaunch">关闭所有页面,打开到应用内2页面</navigator>
  1. <text>pages/4/4.wxml</text>
  2. <navigator url="/pages/3/3" open-type="redirect">关闭当前页面,跳转到应用3页面。但是不允许跳转到 tabbar 页面</navigator>
  1. <text>pages/3/3.wxml</text>
  2. <navigator open-type="navigateBack">关闭当前页面,返回上一页面或多级页面</navigator>

4、生成10个页面,用路由api进行跳转。

编号属性说明
1wx.switchTab跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
2wx.reLaunch关闭所有页面,打开到应用内的某个页面
3wx.redirectTo关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面
4wx.navigateTo保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面
5wx.navigateBack关闭当前页面,返回上一页面或多级页面

app.json

  1. {
  2. "pages":[
  3. "pages/5/5",
  4. "pages/4/4",
  5. "pages/3/3",
  6. "pages/2/2",
  7. "pages/1/1",
  8. "pages/index/index",
  9. "pages/ad/ad",
  10. "pages/art/art",
  11. "pages/admin/admin",
  12. "pages/logs/logs"
  13. ],
  14. "style": "v2",
  15. "sitemapLocation": "sitemap.json",
  16. "window": {
  17. "navigationBarBackgroundColor": "#ffffff",
  18. "navigationBarTextStyle": "black",
  19. "navigationBarTitleText": "默默记账",
  20. "backgroundColor": "#eeeeee",
  21. "backgroundTextStyle": "light",
  22. "enablePullDownRefresh": false
  23. },
  24. "tabBar": {
  25. "color": "#444444",
  26. "selectedColor": "red",
  27. "backgroundColor": "#ffffff",
  28. "position": "bottom",
  29. "borderStyle": "black",
  30. "list": [{
  31. "pagePath": "pages/index/index",
  32. "text": "主页",
  33. "iconPath": "./static/img/1.png",
  34. "selectedIconPath": "./static/img/2.png"
  35. },
  36. {"pagePath": "pages/ad/ad",
  37. "text": "广告",
  38. "iconPath": "./static/img/1.png",
  39. "selectedIconPath": "./static/img/2.png"
  40. },
  41. {"pagePath": "pages/art/art",
  42. "text": "文章",
  43. "iconPath": "./static/img/3.png",
  44. "selectedIconPath": "./static/img/4.png"
  45. },
  46. {
  47. "pagePath": "pages/logs/logs",
  48. "text": "日志",
  49. "iconPath": "./static/img/3.png",
  50. "selectedIconPath": "./static/img/4.png"
  51. }
  52. ]
  53. }
  54. }

5.js

  1. goto4() {
  2. wx.navigateTo({
  3. url: '/pages/4/4',
  4. })
  5. },
  6. gototab() {
  7. wx.switchTab({
  8. url: '/pages/logs/logs',
  9. })
  10. },
  11. goto2() {
  12. wx.reLaunch({
  13. url: '/pages/2/2',
  14. })
  15. },
  16. goto3() {
  17. wx.redirectTo({
  18. url: '/pages/3/3',
  19. })
  20. },

5.wxml

  1. <!--pages/5/5.wxml-->
  2. <text>pages/5/5.wxml</text>
  3. <view bindtap="goto4">navigateTo到页面4</view>
  4. <view bindtap="gototab">wx.switchTab到页面logs</view>
  5. <view bindtap="goto2">wx.reLaunch到页面2</view>
  6. <view bindtap="goto3">wx.redirectTo到页面3</view>

4.js

  1. back5() {
  2. wx.navigateBack({
  3. delta: 0,
  4. })
  5. },

4.wxml

  1. <text>pages/4/4.wxml</text>
  2. <view bindtap="back5">返回上一级页面</view>

5、写出模块化文件,把网络通讯api,做成模块化方法,进行调用

common.js

  1. function getData(city) {
  2. wx.request({
  3. url: 'http://apis.juhe.cn/simpleWeather/query',
  4. method:'POST',
  5. header:{'content-type':'application/x-www-form-urlencoded'},
  6. data:{
  7. city:city,
  8. key:'5eadc4a81863b91579e379704961ee09'
  9. },
  10. success(evt) {
  11. console.log(evt.data.result.future);
  12. }
  13. })
  14. }
  15. const _getData = getData;
  16. export { _getData as getData };

2.js

  1. import {getData} from "../../utils/common";
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. region: ['广东省', '广州', ''],
  8. city:'',
  9. t: []
  10. },
  11. bindRegionChange: function(evt) {
  12. this.setData({
  13. region:evt.detail.value,
  14. city:evt.detail.value[1].slice(0, -1),
  15. // t:getData(this.data.city)
  16. })
  17. getData(this.data.city)
  18. // console.log(this.data.t);
  19. },

2.wxml

  1. <!--pages/2/2.wxml-->
  2. <view class="section">
  3. <view class="section__title">天气</view>
  4. <picker mode="region" bindchange="bindRegionChange" value="{{region}}" custom-item="{{customItem}}">
  5. <view class="picker">
  6. 当前选择:{{region[0]}},{{region[1]}},{{region[2]}}
  7. </view>
  8. </picker>
  9. </view>

更多相关文章

  1. 【记账后台管理系统】用户列表、用户日志列表渲染、记账分类动态
  2. 微信小程序数据操作、自定义事件、微信API、路由组件、变量作用
  3. PHP:【微信小程序】微信小程序API,微信小程序路由,微信小程序作用
  4. 微信小程序介绍、配置、视图层、逻辑层、页面数据交互等知识点学
  5. 【TP实战】记账后台管理系统实战开发(用户管理页面增删改查)
  6. php获取当前的定位城市
  7. PHP:使用curl请求聚合支付的驾考宝典题库接口数据, 并渲染到页面
  8. 本地git的配置和一些命令
  9. 关于获得当前的index的方法

随机推荐

  1. 通过 Android SDK Manager 安装面向 Andr
  2. 常用的布局和View常用属性
  3. Android应用程序开发的五大概念
  4. Eclpise导入android SDK自带的API demos
  5. Android(安卓)json 解析
  6. Android(安卓)BitTube 学习
  7. 第20章、OnCheckedChangeListener事件(从
  8. Android关于线程更新UI的方法
  9. Android(安卓)的属性分析
  10. Android和Linux kernel发展史