1、
request方法
wx.request({
//URL 请求地址
url: '请求地址',
//请求方式
method: 'post',
//
header: {
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
//向后台请求数据
data: {
code: res.code
},
success: function (response) {
//请求成功
},
fail : function(){
//请求失败
}
})
2、
定时器,定时回调方法
setTimeout(() => {
//延迟的方法
this.setData({
loadModal: false
})
}, 500) // 延迟的时间
3、
获取openId的方法
getOpenid: function () {
let that = this;
//获取openid不需要授权
wx.login({
success: function (res) {
//请求自己后台获取用户openid
wx.request({
url: 'https://30paotui.com/user/wechat',
data: {
appid: '自己的AppId',
secret: '自己的secret',
code: res.code
},
success: function (response) {
var openid = response.data.openid;
console.log('请求获取openid:' + openid);
}
})
}
})
},
4、页面跳转
//此页面进入页面栈,并且跳转页也进入页面栈
wx.navigateTo({
url: ' 跳转页面的相对地址 '
});
//此页面出栈,跳转页进栈
wx.redirectTo({
url: ' 跳转页面的相对地址 '
});
5、page中data属性赋值
this.setData({
this.data.属性 : 要附的值 ,
this.data.属性 : 要附的值 ,
});
6、本地缓存(同步)
//存入
wx.setStorageSync(key,value);
//取出
var data = wx.getStorageSync(key);