碧桂园
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

38 righe
1.1 KiB

  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. motto: 'Hello World',
  7. userInfo: {},
  8. hasUserInfo: false,
  9. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  10. canIUseGetUserProfile: false,
  11. canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  12. },
  13. onLoad() {
  14. this.getUserProfile(e)
  15. // if (wx.getUserProfile) {
  16. // this.setData({
  17. // canIUseGetUserProfile: true
  18. // })
  19. // }
  20. },
  21. getUserProfile(e) {
  22. console.log(34)
  23. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  24. wx.getUserProfile({
  25. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  26. success: (res) => {
  27. console.log(res)
  28. this.setData({
  29. userInfo: res.userInfo,
  30. hasUserInfo: true
  31. })
  32. }
  33. })
  34. }
  35. })