Blogger Information
Blog 52
fans 1
comment 1
visits 38664
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0601实战作业
小丑0o鱼
Original
431 people have browsed it

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. },
  11. `
  1. <view bindtap="total" data-a="4" data-b="5">4 + 5 = {{sum}}</view>

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

名称 功能说明

  1. wx.onAppShow 监听小程序切前台事件
  2. wx.onAppHide 监听小程序切后台事件
  3. wx.offAppShow 取消监听小程序切前台事件
  4. wx.offAppHide 取消监听小程序切后台事件
  5. wx.switchTab 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
  6. wx.reLaunch 关闭所有页面,打开到应用内的某个页面
  7. wx.redirectTo 关闭当前页面,跳转到应用内的某个页面
  8. wx.navigateTo 保留当前页面,跳转到应用内的某个页面
  9. wx.navigateBack 关闭当前页面,返回上一页面或多级页面
  10. wx.showToast 显示消息提示框
  11. wx.showModal 显示模态对话框
  12. wx.showLoading 显示 loading 提示框
  13. wx.showActionSheet 显示操作菜单
  14. wx.hideToast 隐藏消息提示框
  15. wx.hideLoading 隐藏 loading 提示框
  16. wx.setStorageSync wx.setStorage 的同步版本
  17. wx.setStorage 将数据存储在本地缓存中指定的 key
  18. wx.removeStorageSync wx.removeStorage 的同步版本
  19. wx.removeStorage 从本地缓存中移除指定 key
  20. wx.getStorageSync wx.getStorage 的同步版本
  21. wx.getStorageInfoSync wx.getStorageInfo 的同步版本
  22. wx.getStorageInfo 异步获取当前storage的相关信息
  23. wx.getStorage 从本地缓存中异步获取指定 key 的内容
  24. wx.clearStorageSync wx.clearStorage 的同步版本
  25. wx.clearStorage 清理本地数据缓存
  26. wx.request 发起 HTTPS 网络请求
  27. wx.uploadFile 将本地资源上传到服务器
  28. wx.downloadFile 下载文件资源到本地

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

navigator 页面链接

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

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

编号 属性 说明

  1. 1 wx.switchTab 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
  2. 2 wx.reLaunch 关闭所有页面,打开到应用内的某个页面
  3. 3 wx.redirectTo 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面
  4. 4 wx.navigateTo 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面
  5. 5 wx.navigateBack 关闭当前页面,返回上一页面或多级页面
  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. 5.js
  2. goto4() {
  3. wx.navigateTo({
  4. url: '/pages/4/4',
  5. })
  6. },
  7. gototab() {
  8. wx.switchTab({
  9. url: '/pages/logs/logs',
  10. })
  11. },
  12. goto2() {
  13. wx.reLaunch({
  14. url: '/pages/2/2',
  15. })
  16. },
  17. goto3() {
  18. wx.redirectTo({
  19. url: '/pages/3/3',
  20. })
  21. },
  22. 5.wxml
  23. <!--pages/5/5.wxml-->
  24. <text>pages/5/5.wxml</text>
  25. <view bindtap="goto4">navigateTo到页面4</view>
  26. <view bindtap="gototab">wx.switchTab到页面logs</view>
  27. <view bindtap="goto2">wx.reLaunch到页面2</view>
  28. <view bindtap="goto3">wx.redirectTo到页面3</view>
  29. 4.js
  30. back5() {
  31. wx.navigateBack({
  32. delta: 0,
  33. })
  34. },
  35. 4.wxml
  36. <text>pages/4/4.wxml</text>
  37. <view bindtap="back5">返回上一级页面</view>
  38. 5、写出模块化文件,把网络通讯api,做成模块化方法,进行调用
  39. common.js
  40. function getData(city) {
  41. wx.request({
  42. url: 'http://apis.juhe.cn/simpleWeather/query',
  43. method:'POST',
  44. header:{'content-type':'application/x-www-form-urlencoded'},
  45. data:{
  46. city:city,
  47. key:'5eadc4a81863b91579e379704961ee09'
  48. },
  49. success(evt) {
  50. console.log(evt.data.result.future);
  51. }
  52. })
  53. }
  54. const _getData = getData;
  55. export { _getData as getData };
  56. 2.js
  57. import {getData} from "../../utils/common";
  58. Page({
  59. /**
  60. * 页面的初始数据
  61. */
  62. data: {
  63. region: ['广东省', '广州', ''],
  64. city:'',
  65. t: []
  66. },
  67. bindRegionChange: function(evt) {
  68. this.setData({
  69. region:evt.detail.value,
  70. city:evt.detail.value[1].slice(0, -1),
  71. // t:getData(this.data.city)
  72. })
  73. getData(this.data.city)
  74. // console.log(this.data.t);
  75. },
  76. 2.wxml
  77. <!--pages/2/2.wxml-->
  78. <view class="section">
  79. <view class="section__title">天气</view>
  80. <picker mode="region" bindchange="bindRegionChange" value="{{region}}" custom-item="{{customItem}}">
  81. <view class="picker">
  82. 当前选择:{{region[0]}},{{region[1]}},{{region[2]}}
  83. </view>
  84. </picker>
  85. </view>
Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post