登陆最新代码报错 requestLogin is undefined

来源:6-4 个人中心-登录逻辑完善

西岚Silan

2018-06-15

登陆代码我更新后,在页面点击登陆的时候会报错,

http://img.mukewang.com/szimg/5b22c43800010e3b06130265.jpg

<template>
<div class="container">
<div class="userinfo" >
<img :src="userinfo.avatarUrl" alt="">
<p>{{userinfo.nickName}}</p>
</div>
<YearProgress></YearProgress>
<button class="btn" v-if="!userinfo.openId" lang="zh_CN" open-type="getUserInfo" @getuserinfo="login">登陆</button>
<button @click="scanBook" class='btn'>添加图书</button>
</div>
</template>
<script>
import { showSuccess, showModal } from '@/util'
import qcloud from 'wafer2-client-sdk'
import config from '@/config'
import YearProgress from '@/components/YearProgress'
export default {
components: { YearProgress },
data() {
    return {
      userinfo: {
        avatarUrl: '../../../static/img/doge.png',
        nickName: 'doge'
      }
    }
  },
methods: {
// encryptedData 为包括敏感数据在内的完整用户信息的加密数据
// iv String 加密算法的初始向量
getWxLogin: function({ encryptedData, iv, userinfo }) {
const self = this
wx.login({
success: function(loginResult) {
console.log('loginResult', loginResult)
var loginParams = {
code: loginResult.code,
encryptedData: encryptedData,
iv: iv
}
qcloud.setLoginUrl(config.loginUrl)
console.log('qcloud.requestLogin', qcloud)
qcloud.requestLogin({
loginParams,
success() {
              // 获取用户信息
              console.log('loginResult', loginResult)
              qcloud.request({
                url: config.userUrl,
                login: true,
                success(userRes) {
                  showSuccess('登录成功')
                  wx.setStorageSync('userinfo', userRes.data.data)
                  self.userinfo = userRes.data.data
                }
              })
            },
fail(error) {
              showModal('登录失败', error)
            }
})
},
fail: function(loginError) {
showModal('登录失败', loginError)
}
})
},
login(e) {
      const self = this // 查看是否授权
      wx.getSetting({
        success: function(res) {
          // 授权信息里有用户信息
          if (res.authSetting['scope.userInfo']) {
            // 检查用户登录是否过期
            wx.checkSession({
              success: function() {
                // 没过期 直接成功
                console.log(res)
                showSuccess('登录成功')
              },
              fail: function() {
                // 过期了 重新登录 先清楚登录的状态
                qcloud.clearSession() // 登录态已过期,需重新登录 // 登录需要的加密信息
                var options = {
                  encryptedData: e.mp.detail.encryptedData,
                  iv: e.mp.detail.iv,
                  userinfo: e.mp.detail.userInfo
                }
                self.getWxLogin(options)
              }
            })
          } else {
            showModal('用户未授权', e.mp.detail.errMsg)
          }
        }
      })
    },
scanBook() {
      wx.scanCode({
        success: res => {
          console.log(res)
        }
      })
    }
},
created() {},
onShow() {
    let userinfo = wx.getStorageSync('userinfo')
    if (userinfo) {
      this.userinfo = userinfo
    }
  }
}
</script>
<style lang='stylus' scoped>
.container {
padding: 0 30px;

.userinfo {
margin-top: 100rpx;
text-align: center;
margin-bottom: 40rpx;

img {
width: 150rpx;
height: 150rpx;
border-radius: 50%;
margin: 20rpx;
}
}
}
</style>

我重新安装wafer2-client-dek也还是报错,

后面我自己翻了他的api接口代码,发现根本没有这个方法。。

http://img.mukewang.com/szimg/5b22c4c4000146a007380613.jpg


我搞不清楚哪里出问题了。。。

写回答

1回答

慕瓜8449030

2018-06-16

你好 咱们代码里的wafer-client-sdk版本请用1.1.3 他们刚两天发布了2.0版本 有点蛋疼,节后我会更新到2.0 并且补录视频说明

0
0

mpvue课程小程序全栈开发

慕课网独家首发 学习mpvue+Koa+vue 全栈开发小程序

1407 学习 · 1331 问题

查看课程