微信小程序提供了一个如同浏览器cookie本地缓存方法,那就是今天要说的wx.setStorageSync()

注意,该方法是同步请求,还有个异步请求的方法是wx.setStorage(),参考官方文档【https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorage.html】

取出本地缓存方法wx.getStorageSync,同样的,它也是异步请求,它也有一个同步请求方法wx.getStorage(),

使用方法如下

登录时候,将所需要存的字段 存入本地缓存中

wx.setStorageSync('userIdEnc', userIdEnc); //将userIdEnc存入本地缓存
wx.setStorageSync('loginDevice', loginDevice);//将loginDevice存入本地缓存

使用时,再从本地缓存 中取出

var userIdEnc = wx.getStorageSync('userIdEnc'); //获取本地缓存中的userIdEnc //用户唯一识别码
var loginDevice = wx.getStorageSync('loginDevice');//获取本地缓存中的loginDevice var header = {
'content-type': 'application/json',
'cookie': "devimark=" + loginDevice + ";" + "usenc=" + userIdEnc,
}; wx.request({
method: "post",
url: 'http://*****.com/createWashingOrder',
data: '{"appId": "' + appid + '", "timestamp": ' + timestamp + ', "version": "' + version + '", "sign": "' + sign + '", "orderAmount": "' + orderAmount + '","modeId": "' + modeId + '","deviceId": "' + deviceId + '","userIdEnc": "' + userIdEnc + '", }@#@1100310183560349',
header: header,
dataType: "json",
success: function (res) {
console.log("请求成功", res)     }, fail: function (res) {
      console.log("请求失败", res)
    }
})

最新文章

  1. OpenCV2:特征匹配及其优化
  2. 升级react 15.4,常见的错误及解决方案
  3. 《Linux内核设计与实现》CHAPTER5阅读梳理
  4. iOS移动开发周报-第21期
  5. 动态加载JS文件,并根据JS文件的加载状态来执行自己的回调函数
  6. 导入cocos2d-x samples android官方示例
  7. 使用 Camtasia Recorder显示 “ camtasia an error occurred in the recorder: video codec open failed ”
  8. VisualStudio中的代码段
  9. PyCrpyto windows安装使用方法
  10. T-SQL编程的基本语法和思想
  11. Neutron 不健全的HA ROUTER
  12. numpy中关于*和dot的区别
  13. Huffman 哈夫曼编码与译码的原理剖析及C++实现
  14. android -------- 沉浸式状态栏和沉浸式导航栏(ImmersionBar)
  15. js cookie 工具
  16. 配置ssh服务允许root管理员直接登录
  17. 【转】Keil ARM开发 error L6236E错误解决
  18. POJ3581 后缀数组
  19. C#中IDisposable的用法
  20. ios8 UITableView section不显示

热门文章

  1. 【python】python环境搭建
  2. 怎样处理jmeter中文乱码
  3. 面试:如何把xxx.sh使用/etc/init.d/xxx.sh start启动,并且可以用chkconfig配置开机自启动
  4. linux的一些权限的操作 chmod
  5. hessian应用示例
  6. Python9-网络编程4-day33
  7. centos7 安装显卡驱动方法
  8. UVA - 11572 Unique Snowflakes 滑动扫描
  9. HTTPS的请求与响应
  10. install redis and used in golang on ubuntu 14.04