vue网易云二维码登录

 html代码

<el-card  v-loading="looogin" class="el_add_card" shadow="hover"> <!-- element-ui卡片 -->
    <img style="width:128px;height:128px" :src="urrl" alt="">
    <button @click="login()" >获取二维码</button>
    <p 
        style="line-height:100px;font-size:16px;"
    >
       <img
         style="width:100px;height:100px;brder-radius:50%;"
       :src="headImg" alt="">
       <span>{{usNName}}</span>
    </p>
</el-card>

 

用到的data

   urrl:'',

   key:'',

   usNName:'',

   cookier:'',

   uid:'',

   headImg:'',

 

事件 

login(){
        let date=new Date();
        this.$axios({
            method: "post",
            url: `http://localhost:3000/login/qr/key?${date.getTime()}`,
            data: '',
        })
        .then((res) => {//获取二维码key
            // console.log(res.data.data.unikey)
            //   this.urrl=res.data.data.qrurl
            this.key=res.data.data.unikey

            let date=new Date
            this.$axios({
                method: "post",
                url: `http://localhost:3000/login/qr/create?${date.getTime()}`,
                data: {
                    key:this.key,
                    qrimg:true
                },
            })
            .then((res) => {//获取二维码图片
                // console.log(res.data.data)
                this.urrl=res.data.data.qrimg
                this.aaaar()
            })
            .catch((error) => {console.log(error)});
        })
        .catch((error) => {console.log(error)});
    },
    aaaar(){
        let timerrr=setInterval(() => {//轮询检索二维码扫描状态
            let date=new Date
            this.$axios({
                method: "post",
                url: `http://localhost:3000/login/qr/check?${date.getTime()}`,
                data: {
                    key:this.key,
                },
            })
            .then((res) => {
                // console.log(res.data.cookie)
                //802:授权中
                //800:授权成功
                //803二维码失效
                if(res.data.code=='802'){
                    this.looogin=true
                }else if(res.data.code=='803'){
                    this.looogin=false
                    this.cookier=res.data.cookie
                    window.clearInterval(timerrr)
                    let date=new Date
                    this.$axios({
                        method: "post",
                        url: `http://localhost:3000/user/account?${date.getTime()}`,
                        data: {
                            cookie:this.cookier,
                        },
                    })
                    .then((res) => {
                        // console.log(res.data)
                        this.uid=res.data.account.id
                        this.usNName=res.data.profile.nickname
                        this.headImg=res.data.profile.avatarUrl
                    })
                    .catch((error) => {console.log(error)});
                }

            })
            .catch((error) => {console.log(error)});
        }, 1000);
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值