后端接口返回个二维码赋值到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(我的项目是这样的,具体看怎么方便)
成功!!!;