Vue获取网页微信登录二维码

首先安装npm install vue-wxlogin --save-dev

<template>
<div id="app">
<div id="wxbox">
<wxlogin :appid="appid" :scope="scope" :redirect_uri="redirect_uri"></wxlogin>
</div>

</div>
</template>

<script>
import wxlogin from 'vue-wxlogin'

export default {
name: 'app',
components: {
wxlogin
},
data () {
return {
appid : 'wxe1f5def243e0390b',
scope : 'snsapi_login',
redirect_uri : 'https://abstest.tenpay.com/abs/author/callBack.do',
}
},
}
</script>

<style>
#wxbox{
width: 400px;
height: 400px;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
vue-wxlogin组件代码,注意这里self_redirect是给的默认值,需要的话可以修改

<template>
<div>
<iframe scrolling="no" width="300" height="400" frameBorder="0" allowTransparency="true" :src="setSrc"></iframe>
</div>
</template>

<script>
export default {
data () {
return {
src: 'https://open.weixin.qq.com/connect/qrconnect?appid=wxe1f5def243e0390b&scope=snsapi_login&redirect_uri=https://abstest.tenpay.com/abs/author/callBack.do&state=0001&login_type=jssdk&self_redirect=default&style=black&href=./wx.css',
// https://open.weixin.qq.com/connect/qrconnect?appid=wxe1f5def243e0390b&scope=undefined&redirect_uri=undefined&state=&login_type=jssdk&self_redirect=default&style=black&href=
}
},
computed : {
setSrc () {
var _url = 'https://open.weixin.qq.com/connect/qrconnect?appid='+ this.appid
+ '&scope=' + this.scope
+ '&redirect_uri=' + this.redirect_uri
+ '&state=' + this.state
+ '&login_type=jssdk&self_redirect=default&style=' + this.theme
+ '&href=' + this.href;
return _url;
},
},
props:{
//应用唯一标识,在微信开放平台提交应用审核通过后获得
appid : String,
//应用授权作用域,拥有多个作用域用逗号(,)分隔,网页应用目前仅填写snsapi_login即可
scope : String,
//重定向地址,需要进行UrlEncode
redirect_uri : String,
//用于保持请求和回调的状态,授权请求后原样带回给第三方。该参数可用于防止csrf攻击(跨站请求伪造攻击),建议第三方带上该参数,可设置为简单的随机数加session进行校验
state : {
type : String,
default: ''
},
//提供"black"、"white"可选,默认为黑色文字描述。详见文档底部FAQ
theme : {
type : String,
default: 'black'
},
// 自定义样式链接,第三方可根据实际需求覆盖默认样式。详见文档底部FAQ
href : {
type : String,
default: ''
},
},
}
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

点赞

评论

分享

收藏

手机看

打赏
文章举报
xiaozhuge_S
558

在Vue中调起微信扫描二维码功能(前端
————————————————
版权声明:本文为CSDN博主「阿燃i」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/OCEAN_C/article/details/106325859

猜你喜欢

转载自www.cnblogs.com/mahuang/p/12956123.html