アプレットが getUserInfo を使用してユーザー情報を取得できない

1.getUserInfoを使用する

 wx.getUserInfo({
    
    
      success: (res) => {
    
    
        console.log(res);
        this.setData({
    
    
          userInfo: res.userInfo
        })
      },
      fail: (err) => {
    
    
        console.log(err);
      }
    })
  },

取得される情報、
ここに画像の説明を挿入
つまりユーザーのアバターやニックネームは取得できません

2. 理由

新しいバージョンの WeChat 開発ツールでは、wx.getUserProfile を使用してユーザー情報を取得することを推奨しています

getUserProfile(e) {
    
    
    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    wx.getUserProfile({
    
    
      desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
    
    
        console.log(res)
        this.setData({
    
    
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },

3. getUserInfo を使用する必要がある場合はどうすればよいですか?

答え: はい

方法は、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": []
        }
    }
}

旧バージョンのユーザー情報取得の影響は以下のとおりです。
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/CathyleeQ/article/details/124371062