批改状态:未批改
老师批语:
事件对象可以携带额外信息,通过使用data- 自定义传值
方法使用evt.target.dataset.获取传的值
data: {sum: 0},// 自定义方法total(evt) {this.setData({sum: evt.target.dataset.a*1 + evt.target.dataset.b*1})console.log(this.data.sum);},`
<view bindtap="total" data-a="4" data-b="5">4 + 5 = {{sum}}</view>
名称 功能说明
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.setStorageSync wx.setStorage 的同步版本wx.setStorage 将数据存储在本地缓存中指定的 key 中wx.removeStorageSync wx.removeStorage 的同步版本wx.removeStorage 从本地缓存中移除指定 keywx.getStorageSync wx.getStorage 的同步版本wx.getStorageInfoSync wx.getStorageInfo 的同步版本wx.getStorageInfo 异步获取当前storage的相关信息wx.getStorage 从本地缓存中异步获取指定 key 的内容wx.clearStorageSync wx.clearStorage 的同步版本wx.clearStorage 清理本地数据缓存wx.request 发起 HTTPS 网络请求wx.uploadFile 将本地资源上传到服务器wx.downloadFile 下载文件资源到本地
{"pages":["pages/5/5","pages/4/4","pages/3/3","pages/2/2","pages/1/1","pages/index/index","pages/ad/ad","pages/art/art","pages/admin/admin","pages/logs/logs"],"style": "v2","sitemapLocation": "sitemap.json","window": {"navigationBarBackgroundColor": "#ffffff","navigationBarTextStyle": "black","navigationBarTitleText": "默默记账","backgroundColor": "#eeeeee","backgroundTextStyle": "light","enablePullDownRefresh": false},"tabBar": {"color": "#444444","selectedColor": "red","backgroundColor": "#ffffff","position": "bottom","borderStyle": "black","list": [{"pagePath": "pages/index/index","text": "主页","iconPath": "./static/img/1.png","selectedIconPath": "./static/img/2.png"},{"pagePath": "pages/ad/ad","text": "广告","iconPath": "./static/img/1.png","selectedIconPath": "./static/img/2.png"},{"pagePath": "pages/art/art","text": "文章","iconPath": "./static/img/3.png","selectedIconPath": "./static/img/4.png"},{"pagePath": "pages/logs/logs","text": "日志","iconPath": "./static/img/3.png","selectedIconPath": "./static/img/4.png"}]}}
编号 属性 说明
1 wx.switchTab 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面2 wx.reLaunch 关闭所有页面,打开到应用内的某个页面3 wx.redirectTo 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面4 wx.navigateTo 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面5 wx.navigateBack 关闭当前页面,返回上一页面或多级页面
{"pages":["pages/5/5","pages/4/4","pages/3/3","pages/2/2","pages/1/1","pages/index/index","pages/ad/ad","pages/art/art","pages/admin/admin","pages/logs/logs"],"style": "v2","sitemapLocation": "sitemap.json","window": {"navigationBarBackgroundColor": "#ffffff","navigationBarTextStyle": "black","navigationBarTitleText": "默默记账","backgroundColor": "#eeeeee","backgroundTextStyle": "light","enablePullDownRefresh": false},"tabBar": {"color": "#444444","selectedColor": "red","backgroundColor": "#ffffff","position": "bottom","borderStyle": "black","list": [{"pagePath": "pages/index/index","text": "主页","iconPath": "./static/img/1.png","selectedIconPath": "./static/img/2.png"},{"pagePath": "pages/ad/ad","text": "广告","iconPath": "./static/img/1.png","selectedIconPath": "./static/img/2.png"},{"pagePath": "pages/art/art","text": "文章","iconPath": "./static/img/3.png","selectedIconPath": "./static/img/4.png"},{"pagePath": "pages/logs/logs","text": "日志","iconPath": "./static/img/3.png","selectedIconPath": "./static/img/4.png"}]}}
5.jsgoto4() {wx.navigateTo({url: '/pages/4/4',})},gototab() {wx.switchTab({url: '/pages/logs/logs',})},goto2() {wx.reLaunch({url: '/pages/2/2',})},goto3() {wx.redirectTo({url: '/pages/3/3',})},5.wxml<!--pages/5/5.wxml--><text>pages/5/5.wxml</text><view bindtap="goto4">navigateTo到页面4</view><view bindtap="gototab">wx.switchTab到页面logs</view><view bindtap="goto2">wx.reLaunch到页面2</view><view bindtap="goto3">wx.redirectTo到页面3</view>4.jsback5() {wx.navigateBack({delta: 0,})},4.wxml<text>pages/4/4.wxml</text><view bindtap="back5">返回上一级页面</view>5、写出模块化文件,把网络通讯api,做成模块化方法,进行调用common.jsfunction getData(city) {wx.request({url: 'http://apis.juhe.cn/simpleWeather/query',method:'POST',header:{'content-type':'application/x-www-form-urlencoded'},data:{city:city,key:'5eadc4a81863b91579e379704961ee09'},success(evt) {console.log(evt.data.result.future);}})}const _getData = getData;export { _getData as getData };2.jsimport {getData} from "../../utils/common";Page({/*** 页面的初始数据*/data: {region: ['广东省', '广州', ''],city:'',t: []},bindRegionChange: function(evt) {this.setData({region:evt.detail.value,city:evt.detail.value[1].slice(0, -1),// t:getData(this.data.city)})getData(this.data.city)// console.log(this.data.t);},2.wxml<!--pages/2/2.wxml--><view class="section"><view class="section__title">天气</view><picker mode="region" bindchange="bindRegionChange" value="{{region}}" custom-item="{{customItem}}"><view class="picker">当前选择:{{region[0]}},{{region[1]}},{{region[2]}}</view></picker></view>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号