当前位置: 首页 > Web前端 > vue.js

VueWeChatscancodelogin,customstyle

时间:2023-03-31 16:47:06 vue.js

vueWeChatscancodeloginusingpluginhttps://www.npmjs.com/package/vue-wxlogin//Installnpminstallvue-wxlogin--save-dev//componentIntroduceimportwxloginfrom'vue-wxlogin'...components:{wxlogin}...HTMLuses参数说明appid:应用唯一标识(前面认证网页应用中获得)scope:应用授权作用域,拥有多个作用域用逗号Separatedby(,),webapplicationscurrentlyonlyneedtofillinsnsapi\_logintheme:"black"and"white"areavailable,andthedefaultisblacktextdescription.redirect_uri:回调地址href:自定义样式链接,仅https链接或base64编码地址href自定义样式1.使用https链接地址。这个很简单,把自定义的css文件上传到服务器,然后在服务器上使用css文件即可(缺点:如果网速慢,先加载默认样式,再使用自定义样式,有一个刷机过程)2.使用base64http://tool.chinaz.com/Tools/...(站长工具,转换base64编码工具)//自定义二维码style.impowerBox.title{display:none;}.impowerBox.status.status_browser{显示:无;}.impowerBox.qrcode{边框:无;宽度:200px;height:200px;}.impowerBox.status{display:none}3.href必须使用text/css模式,生成的base64添加到'data:text/css;base64,'后面就可以了href="data:text/css;base64,LmltcG93ZXJCb3ggLnRpdGxlIHsNCiAgZGlzcGxheTogbm9uZTsNCn0NCi5pbXBvd2VyQm94IC5zdGF0dXMuc3RhdHVzX2Jyb3dzZXIgew0KICBkaXNwbGF5OiBub25lOw0KfQ0KLmltcG93ZXJCb3ggLnFyY29kZSB7DQogIGJvcmRlcjogbm9uZTsNCiAgd2lkdGg6IDIwMHB4Ow0KICBoZWlnaHQ6IDIwMHB4Ow0KfQ0KLmltcG93ZXJCb3ggLnN0YXR1c3sNCiAgZGlzcGxheTogbm9uZQ0KfQ=="4、需要注意的地方redirect_uri:回调地址,必须使用encodeURLComponent()编码5、RegardingthesuccessfulcallbackinterfaceofVuescancode,theproblemofjumping.回调接口路由设置这个接口的路由一直都是。扫码成功后,地址栏会增加“code”和“state”查询参数。我们可以通过手表检测$route.query参数的变化,从而知道扫码成功,然后我们可以设置setTimeout等待几秒关闭二维码弹窗并跳转到原来的路由地址。watch:{'$route.query'(newVal,oldVal){if(newVal.num){让pm=newFormData()pm.append('code',this.$route.query.code)pm.append('state',this.$route.query.state)pm.append('user_id',this.user_id)WECHAT_CALLBACK(pm).then(res=>{console.log(res)if(res.unbindUserInfo){this.personInfo.wx_headimgurl=res.unbindUserInfo.wxHeadimgurl}this.scanSuccess=true}).catch(error=>{console.log(error)})setTimeout(()=>{this.wechatState=falsethis.$router.replace({name:'structure'})},2000)}console.log(newVal,oldVal,'watchinformationchange')}},