Vue获取微博授权URL代码实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Vue获取微博授权URL代码实例

周晓楠   2020-11-04 我要评论

1.在Vue页面加载时动态发送请求获取微博授 权url

1.1 在 components\common\lab_header.vue 中写oauth动态获取微 博授权URL

// 获取微博登录地址
oauth() {
  // 从后端获取 微博登录地址
  oauth_post().then((resp) => {
    console.log(resp)
    //{'code': '0', 'msg': '成功', 'data': {'url': url}}
    let url = resp.data.url;
    this.weibo_url = url;
  })
},

1.2 在vue的mounted函数中调用获取微博授权url函数

mounted() {
  this.oauth()
},

1.3 点击"登录"弹出的form表单中加入url

<form
  action="/login"
  method="post"
>
  <div class="form-group widget-signin">
    <a :href="weibo_url" rel="external nofollow" ><i class="fa fa-weibo"></i></a>
  </div>
</form>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们