一、全局变量:
globalData:{}
二、子页面调用全局data数据:
var app=getApp();
app.globalData.XXXX
三、下拉刷新:
1》首先子页面的.json里面:
"enablePullDownRefresh": true;
2》然后.js里面:
onPullDownRefresh:function()
{
wx.showNavigationBarLoading() //在标题栏中显示加载
//模拟加载
setTimeout(function()
{
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},1500);
}
//setTimeout(code,millisec);
//方法用于在指定的毫秒数**后**调用函数或计算表达式。
//可以较为直观的观察到加载过程
}
四、设置页面标题
1>静态设置
在.json中设置
"navigationBarTitleText": "XXXXX",
2>动态设置
在.js中
wx.setNavigationBarTitle({
title: '当前页面'
})
//动态设置优先级高于静态设置
五、网络请求
wx.request({
url: '字符串', //仅为示例,并非真实的接口地址
data: {
x: '' ,
y: ''
},
method:'psot',
dataType:'json',//如果设为json,会尝试对返回的数据做一次 JSON.parse(text)==将一个字符串转换成json数组
header: {
'content-type': 'application/json' // 默认值
},
success: function(res) {
console.log(res.data)
},
fail: function(res) {
console.log(res.data)
}
})
六、弹窗提示
//显示消息提示框
wx.showToast({
title: '成功',
icon: 'success',//图标,有效值 "success", "loading", "none"
duration: 2000//提示的延迟时间,单位毫秒,默认:1500
image:'',//自定义图标的本地路径,image 的优先级高于 icon
})
//显示loading提示框
wx.showLoading({
title: '加载中',
})
setTimeout(function(){
wx.hideLoading()
},2000)
//showLoading()中不可以用setTimeout(),应该如上所示操作,并且显示Loading提示框可以在下拉刷新的时候调用
//显示模态弹窗
wx.showModal({
title: '提示',
content: '这是一个模态弹窗',
showCancel:true,//是否显示取消按钮,默认为 true
cancelText:'XX',//取消按钮的文字,默认为"取消",最多 4 个字符
cancelColor:'',//取消按钮的文字颜色,默认为"#000000"
confirmText:'',//确定按钮的文字,默认为"确定",最多 4 个字符
confirmColor:'',//确定按钮的文字颜色,默认为"#3CC51F"
success: function(res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
七、设置data数据
八、导航跳转
九、