1.使用getUserInfo wx.getUserInfo({ success: (res) => { console.log(res); this.setD
wx.getUserInfo({ success: (res) => { console.log(res); this.setData({ userInfo: res.userInfo }) }, fail: (err) => { console.log(err); } }) },
获取得到的信息:
也就是不能获取用户的头像和昵称
新版的微信开发工具推荐使用wx.getUserProfile获取用户信息
getUserProfile(e) { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) },
答案:可以
做法,把project.config.JSON版本换成老版本。老版本就可以使用getUserInfo获取用户信息了。当然官方都推荐用新的了,咱还是用新的吧,省事。
(老版本如下)
{ "description": "项目配置文件", "packOptions": { "ignore": [] }, "setting": { "urlCheck": true, "es6": true, "enhance": true, "postCSS": true, "preloadBackgroundData": false, "minified": true, "newFeature": true, "coverView": true, "nodeModules": false, "autoAudits": false, "showShadowRootInWxmlPanel": true, "scopeDataCheck": false, "uglifyFileName": false, "checkInvalidKey": true, "checkSiteMap": true, "uploadWithSourceMap": true, "compileHotReLoad": false, "lazyloadPlaceholderEnable": false, "useMultiFrameRuntime": true, "useapiHook": true, "useApiHostProcess": true, "babelSetting": { "ignore": [], "disablePlugins": [], "outputPath": "" }, "useIsolateContext": true, "userConfirmedBundleSwitch": false, "packNpmManually": false, "packNpmRelationList": [], "minifyWXSS": true, "disableUseStrict": false, "minifyWXML": true, "showES6CompileOption": false, "useCompilerPlugins": false, "ignoreUploadUnusedFiles": true }, "compileType": "miniprogram", "libVersion": "2.13.1", "appid": "wx7a5dfd35d20f6982", "projectname": "wechat_study", "debuGoptions": { "hidedInDevtools": [] }, "isGameTourist": false, "simulatorType": "wechat", "simulatorPluginLibVersion": {}, "condition": { "search": { "list": [] }, "conversation": { "list": [] }, "game": { "currentL": -1, "list": [] }, "miniprogram": { "list": [] } }}
老版获取用户信息效果如下:
来源地址:https://blog.csdn.net/CathyleeQ/article/details/124371062
--结束END--
本文标题: 小程序使用getUserInfo获取用户信息失败
本文链接: https://www.lsjlt.com/news/395583.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0