关于mpvue和wafer2-client-sdk的 微信登录失败,请检查网络状态

关于mpvue和wafer2-client-sdk的登录使用。

错误形式:

<script>
// import {get} from './util'
import qcloud from 'wafer2-client-sdk'
import config from './config.js'

export default {
  async created () {
    qcloud.setLoginUrl(config.loginUrl)
    qcloud.login({
      success: function (userInfo) {
        console.log('登录成功', userInfo)
      },
      fail: function (err) {
        console.log('登录失败', err)
      }
    })
  }
}
</script>

<style>
</style>

错误原因:以上接口已经被微信废弃,但为了兼容暂时没有去除。

由于微信的 wx.getUserInfo 不再弹窗授权,得修改为 button 弹窗获取用户信息。

正确规范:

<template>
    <div id="persons">
        <button open-type="getUserInfo" lang="zh_CN" @getuserinfo="doLogin">获取用户信息</button>
    </div>
</template>

<script>
  import qcloud from 'wafer2-client-sdk'
  import config from '@/config.js'
  export default {
    methods: {
      doLogin: function (e) {
        qcloud.setLoginUrl(config.loginUrl)
        qcloud.login({
          success: function (userInfo) {
            console.log('登录成功', userInfo)
          },
          fail: function (err) {
            console.log('登录失败', err)
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>

 

posted @ 2018-09-18 16:45  泠风lj  阅读(840)  评论(0编辑  收藏  举报