[微信小程序]使用getphonenumber获取手机号问题? [想知道什么直接问不就好了。]

getPhoneNumber(e) {
      console.log("1111")
      if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
        wx.showModal({
          title: "提示",
          showCancel: false,
          content: "未授权",
          success: function(res) {}
        });
      } else {
        wx.showModal({
          title: "提示",
          showCancel: false,
          content: "同意授权",
          success: function(res) {
            // 用户登录
            wx.login({
              success: res => {
                console.log("code转换", res.code); //用code传给服务器调换session_key
                wx.request({
                  url: "http://127.0.0.1:3030/wechat/login", //接口地址
                  data: {
                    code: res.code
                  },
                  success: res => {
                    wx.setStorageSync("openid", res.data.openid);
                    wx.setStorageSync("session_key", res.data.session_key);
                    console.log(res);
                    wx.request({
                      url: "http://127.0.0.1:3030/wechat/wxbizdatacrypt",
                      data: {
                        encryptedData: e.detail.encryptedData,
                        iv: e.detail.iv,
                        session_key: wx.getStorageSync("session_key")
                      },
                      success: res => {
                        console.log(res);
                      }
                    });
                  }
                });
              }
            });
          }
        });
      }
    },


一直报:Component "pages/sign/sign" does not have a method "getPhoneNumber" to handle event "getphonenumber".

  • 应该是函数大小写问题吧。你在wxml写的事件和在js里面的大小写不一致,导致找不到这个函数, 搞不清楚你在说什么。
    • , 如果你什么都不说,我也不知道怎么回答你呀
    • 实际测试了下,并不会出现你这问题,应该是你代码哪里写的有问题 个人建议  你这代码完全可以压缩 这个模态框没啥必要,因为会出来授权窗口 这两次请求完全可以合并到一起 , 此刻 我更愿意保持沉默
    • 因为用的mpvue很多地方有问题,还是要好好研究下, 正在研究中