收藏
回答

TypeScript开发,真机调试时,App()不被调用

框架类型 问题类型 终端类型 微信版本 基础库版本
小程序 Bug 工具 8.0.15 2.20.0

开放者工具版本:1.05.2110110

按向导创建项目,语言选择typescript,发现真机调试时,在页面里调用getApp()返回undefined

语言选择js,则正常

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs',
    })
  },
  onLoad() {
    console.log('---------index.onLoad---------')
    console.log(getApp<IAppOption>())
    // @ts-ignore
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容