VUE_vue微信授权页面

在这里插入图片描述

<!-- 微信授权 -->
<template>
    <div>
        <Header :title="'微信授权'" />
        
        <div class="wechat">
            <div class="wechat_">

                <div class="wechat_top">
                    <img src="../../assets/user/weixin.png" alt="">
                    <div class="wechat_top_title">微信授权</div>
                    <div class="wechat_top_xian"></div>
                </div>

                <div class="wechat_min">
                    <div class="wechat_min_title">
                        网页由该公众号开发,请求确定授权一下信息
                    </div>
                    <div class="wechat_min_txt">
                       ● 获取你的公开信息(昵称、头像等)
                    </div>
                </div>

                <div class="wechat_btn" @click="onwechat">确定授权</div>

            </div>
        </div>
    </div>
</template>
<script>
import Header from '../layout/header'			//头部组件没有则删除
import { Toast  } from 'vant';
export default {
    data() {
        return {
            power:"https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri="授权后重定向的回调链接地址"&response_type=code&scope=snsapi_userinfo#wechat_redirect
",           //授权地址
        }
    },
    created(){
        this.onweixintwo()
    },
    mounted() {
        
    },
    methods:{
        //获取url参数
        urldata(name){
            //构造一个含有目标参数的正则表达式对象
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            //匹配目标参数
            var r = window.location.search.substr(1).match(reg);
            //返回参数值
            if (r!=null) return unescape(r[2]);
            return null;
        },
        //授权按钮
        onwechat(){
            var ua = navigator.userAgent.toLowerCase();			//判断是否是微信浏览器
            var isWeixin = ua.indexOf('micromessenger') != -1;	//判断是否
            if (!isWeixin) {
                Toast("请在微信浏览器中打开");
                return false;
            }else{
                window.location.href=this.power
            }
            
        },
        //绑定授权
        onweixintwo(){
            let code = this.urldata('code')
            if(!code){
                return false;
            }
           	//这里拿到code发起请求
            console.log(code)
        },
    },
    components:{
        Header,
    }
};
</script>
<style scoped>

.wechat{
    width: 100vw;
    height: 100vh;
    background: #fff;
    overflow: hidden;
    margin-top: -46px;
}
.wechat_{
    width: 300px;
    height: 100%;
    min-height: 550px;
    margin: 0 auto;
    text-align: left;
}
.wechat_top{
    text-align: center;
    font-size: 24px;
    margin-top: 96px;
}
.wechat_top >img{
    width: 100px;
    height: 100px;
    border-radius: 7px;
}
.wechat_top_title{
    padding-top: 10px;
}
.wechat_top_xian{
    width: 300px;
    height: 1px;
    background: #f5f5f5;
    margin-top: 30px;
}

.wechat_min{
    width: 100%;
    padding-top: 30px;
}
.wechat_min_title{
    font-size: 18px;
}
.wechat_min_txt{
    font-size: 16px;
    color: #777;
    padding-top: 20px;
}

.wechat_btn{
    width: 300px;
    height: 49px;
    line-height: 49px;
    text-align: center;
    background: #00cc00;
    font-size: 24px;
    color: #fff;
    border-radius: 7px;
    margin-top: 50px;
}
</style>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值