小程序遇到的问题

mac2025-11-07  1

小程序遇到的问题

1.获取openid

// 获取用户信息 wx.getSetting({ success: res => { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 wx.getUserInfo({ success: res => { // 可以将 res 发送给后台解码出 unionId var app = getApp() app.globalData.userInfo = res.userInfo //console.log(res.userInfo) //console.log(app.globalData.userInfo) if (this.userInfoReadyCallback) { this.userInfoReadyCallback(res) } // 登录 wx.login({ success(res) { console.log(res.code) wx.request({ url: 'https://api.weixin.qq.com/sns/jscode2session', data: { appid: 'wx529edc8c28e369ee', secret: '041fb4bf12fe71a439fe9520e6ebd08f', js_code: res.code, grant_type: 'authorization_code' }, method: "GET", success: function (res) { //ajax 提交把openid保存到数据库中 var app = getApp(); console.log(app.globalData.userInfo) if (app.globalData.userInfo != null) { wx.request({ url: 'http://localhost:8080/user/', data: { openId: res.data.openid, nickName: app.globalData.userInfo.nickName, gender: app.globalData.userInfo.gender, avatarUrl: app.globalData.userInfo.avatarUrl, language: app.globalData.userInfo.language }, method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success(res) { console.log("提交用户信息成功的回调函数" + res) } }) } app.globalData.openid = res.data.openid; console.log("app.globalData.openid--------" + app.globalData.openid) } }) } }) } }) } } }) }, Now you can provide attr wx:key for a wx:for to improve performance. <block wx:for="{{items}}"> <block wx:for="{{items}}" wx:key='key'> <block wx:for="{{items}}" wx:key='key' wx:for-item='itme'>

django对象序列化为json

Django ORM的 Queryset对象默认无法被直接json.dumps()序列化,django.core提供的serializers模块可以将其序列化成str类型。

def tabledata(request): mon = MonRota.objects.all().filter(s_time__startswith='2018-02-10') json_data = serializers.serialize('json', mon) json_data = json.loads(json_data) return JsonResponse(json_data, safe=False)

[django对象序列化为json]https://www.jianshu.com/p/ac03b77769f2

Cannot read property ‘setData’ of undefined;at api request success callback function

TypeError: Cannot read property ‘setData’ of undefined! 解决方法:

最新回复(0)