通过调用后台接口获取openid
2019-07-24 本文已影响0人
小睿同学
export default{
data(){
return{
code:"",
openid:"" //通过调用后台接口获取的openid
}
}
}
methods: {
getOpenid(code) {
return this.$fetcher(" ", { code });//后台的接口
},
async getOpenidHandle(code) {
try {
let res = await this.getOpenid(code);
if (res.data.code == 100) {
this.openid = res.data.extend.openid;
this.hasWechatLogin = true;
//alert(`openid: ${this.openid}`);通过alert 可以测试是否有openid
} else {
this.hasWechatLogin = false;
}
} catch (error) {
console.error(`获取openid异常: ${error}`);
}
},
}