created () {
this.getCode()
},
getCode () {
const code = this.getUrlParam('code')
const local = window.location.href
console.log(code)
if (code == null || code === '') {
window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=[你的公众号AppID]&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
} else {
this.code=code;
}
},
getUrlParam: function (name) {
var reg=new RegExp('(^|&)'+name+'=([^&]*)(&|$)')
var r=window.location.search.substr(1).match(reg)
if(r!=null) return unescape(r[2])
return null
},