美文网首页
通过调用后台接口获取openid

通过调用后台接口获取openid

作者: 小睿同学 | 来源:发表于2019-07-24 09:05 被阅读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}`);
            }
        },
}

相关文章

网友评论

      本文标题:通过调用后台接口获取openid

      本文链接:https://www.haomeiwen.com/subject/xjrtrctx.html