vue 微信公众号项目获取code
2020-06-06 本文已影响0人
Do_Du
getFormList(){
getFormList({id:this.id }).then(res => {
if (window.location.search.indexOf('code') < 0) { // 当前的url地址不存在code 就跳转到服务端返回的微信地址
window.location.href = res
} else if (window.location.search.indexOf('code') > -1) {
// alert(window.location.href)
// alert(this.getUrlKey('code'))
var code = this.getUrlKey('code')
getFormList({id: this.id }).then(res => {
this.list = res.data
this.openid = res.wxuserinfo.openid
})
}
})
},
getUrlKey: function(name) { // 截取地址栏参数
return decodeURIComponent(
(new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
},