util.getUserInfo(callback)

获取成功后会将用户信息写入到缓存中,如果指定了回调函数,则会调用回调函数

  • callback 获取成功后的回调函数

示例

  1. var app = getApp()
  2. Page(
  3. onLoad: function () {
  4. var that = this
  5. app.getUserInfo(function (userInfo) {
  6. //更新数据
  7. that.setData({
  8. userInfo: userInfo
  9. });
  10. });
  11. }
  12. });

util.request(option)

此函数是扩展小程序的wx.request函数,您请求模块中的接口数据时,必须使用此函数请求,模块中才可以获取到用户的身份信息和签名安全验证

  • option.cachetime 缓存时间,在此周期内不重复请求,默认不缓存 获取成功后的回调函数

示例

  1. function getHotelList(cb) {
  2. app.util.request({
  3. url: \'entry/wxapp/hotellists\',
  4. data: {
  5. m: \'ewei_hotel\',
  6. },
  7. cachetime: 30,
  8. success: function (res) {
  9. if (res.data.errno == 0) {
  10. typeof cb == "function" && cb(res);
  11. } else {
  12. failGo(res.data.message);
  13. }
  14. },
  15. fail: function () {
  16. failGo(\'请检查连接地址\');
  17. }
  18. })
  19. }

util.url(action, querystring)

与微擎系统中的 url() 函数一致

  • action 微擎系统中的controller, action, do,格式为 \’wxapp/home/navs\’
  • querystring 格式为 {参数名1 : 值1, 参数名2 : 值2}

示例

  1. util.url(\'entry/wxapp/hotellists\', {m : \'ewei_hotel\'});
  2. //地址为:https://pro.we7.cc/app/index.php?i=8641&t=8907&c=entry&a=wxapp&do=hotellists&state=we7sid-89d565916d5496ef322630a73f170f99&sign=c6ab3b6fd8d564419e7fb7e809e3efba&m=ewei_hotel

版权声明:本文为ldms原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/ldms/p/8310325.html