index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. lb:[
  7. {
  8. url:'',
  9. text: '中国科学家实现“量子计算优越性”里程碑'
  10. },
  11. {
  12. url: '',
  13. text: '中国科学家实现“量子计算优越性”里程碑'
  14. },
  15. {
  16. url: '',
  17. text: '中国科学家实现“量子计算优越性”里程碑'
  18. }
  19. ]
  20. },
  21. //事件处理函数
  22. bindViewTap: function() {
  23. wx.navigateTo({
  24. url: '../logs/logs'
  25. })
  26. },
  27. onLoad: function () {
  28. if (app.globalData.userInfo) {
  29. this.setData({
  30. userInfo: app.globalData.userInfo,
  31. hasUserInfo: true
  32. })
  33. } else if (this.data.canIUse){
  34. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  35. // 所以此处加入 callback 以防止这种情况
  36. app.userInfoReadyCallback = res => {
  37. this.setData({
  38. userInfo: res.userInfo,
  39. hasUserInfo: true
  40. })
  41. }
  42. } else {
  43. // 在没有 open-type=getUserInfo 版本的兼容处理
  44. wx.getUserInfo({
  45. success: res => {
  46. app.globalData.userInfo = res.userInfo
  47. this.setData({
  48. userInfo: res.userInfo,
  49. hasUserInfo: true
  50. })
  51. }
  52. })
  53. }
  54. },
  55. getUserInfo: function(e) {
  56. console.log(e)
  57. app.globalData.userInfo = e.detail.userInfo
  58. this.setData({
  59. userInfo: e.detail.userInfo,
  60. hasUserInfo: true
  61. })
  62. }
  63. })