赞
踩
this.setData({ show: true });
{
"window":{"navigationStyle":"custom"}
}
navTo() {
wx.navigateTo({
url: '/pages/index/index'
})
},
1.缓存获取:
wx.getStorageSync('UserData')
2.存入缓存:
wx.setStorageSync('UserData')
utils文件下api.js
let host = "后端接口地址"
let api = {
getLogin: `${host}功能接口路径`,
}
module.exports = api
let param = {
API_URL: api.(接口)+id,
method: "GET",
};
let data = {id}
let param = {
data,
API_URL: api.(接口),
method: "POST",
};
import api from './utils/api' GET、SET请求 getData.result(param).then((res) => { wx.hideLoading() if (res.statusCode == 200) { wx.showToast({ title: '指派成功', icon: 'success', duration: 1000 }) } else { wx.showToast({ title: '请稍后重试', icon: 'error', duration: 1000 }) } })
<view wx:for="{{列表}}" wx:key="index">
<view bindtap="事件名" data-item="{{item}}">{{item.id}</view>
</view>
事件名: function(event){
console.log(event.currentTarget.dataset.item.id;);
}
//app.json中
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos": [ "getLocation","onLocationChange","startLocationUpdateBackground"],
//位置坐标 shouLocation() { let that = this wx.getLocation({ type: 'wgs84', success(res) { const latitude = res.latitude const longitude = res.longitude that.setData({ 'form.location': '{"lat":' + res.latitude + ',"lng":' + res.longitude + '}', location: '已获取' }) Notify({ type: 'primary', message: '已获取成功', duration: 700, }); }, }) },
// 获取用户code wx.login({ success: function (res) { console.log(res); // 发送静默登录请求 wx.request({ url: api.byCode, method: 'POST', data: { code: res.code }, success: function (response) { console.log('登陆成功',response); // 将token和用户信息存储到本地缓存中 wx.setStorageSync('token', response.data.access_token) wx.setStorageSync('UserData', response.data.data) console.log(wx.getStorageSync('UserData')); } }) } })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。