后端接口返回个二维码赋值到iframe
iframe必须加sandbox=“allow-scripts allow-top-navigation allow-same-origin”
不然会报错

代码


<template>
  <div>
    <iframe
      sandbox="allow-scripts allow-top-navigation allow-same-origin"
      :src="qrCode"
      frameborder="0"
      scrolling="auto"
      style="width:400px;height:400px;"
    >
    </iframe>
  </div>
</template>
mounted() {
    this.getWx()
  },
  methods: {
    getWx() {
    //将接口返回的二维码赋值到iframe
      this.$axios
        .get('****/wxLogin')
        .then((res) => {
          console.log(res.data)
          this.qrCode = res.data
        })
        .catch(function (error) {
          console.log(error)
        })
    },
    getLogin(code) {
    //将接口返回的二维码赋值到iframe
      this.$axios
        .post('****/login',{
        code:"xxx"
        })
        .then((res) => {
          console.log(res.data)
          this.qrCode = res.data
        })
        .catch(function (error) {
          console.log(error)
        })
    },

扫描二维码登录点确定后。后台返回地址为当前项目链接并带上openid(我的项目是这样的,具体看怎么方便)

成功!!!;

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐