终端下载包 npm install --save qrcode
// 引入二维码包 二维码生成
import QRCode from 'qrcode'
// 创建二维码事件 QRCode
CreateQrCode() {
const checkedNames = []
let groupOptionArray = []
// checked选项转为数组
for (let prop in this.groupOptionData) {
groupOptionArray.push(this.groupOptionData[prop])
}
// console.log(groupOptionArray, 'groupOptionArray')
groupOptionArray.forEach((item, index) => {
if (item) {
console.log(this.currentContain, 'this.currentContain.scopes[index]')
if (this.currentContain.scopes.length > 1) {
checkedNames.push(this.currentContain.scopes[index])
}
}
})
let checkedStr = checkedNames.toString()
// console.log(checkedStr, 'checkedStr')
let { id } = this.$route.query
let token = getToken()
let windowHref = window.location.origin
console.log(windowHref, 'windowHref')
// 给路径前加http://可以直接打开你的路径 扫描二维码跳转网页功能
let QRqueryData = `${windowHref}/portal-app/preview?id=${id}&scopes=${checkedStr}&access_token=${token}`
console.log(QRqueryData, 'QRqueryData')
// mode为类型 data为你的qr二维码信息
const segs = [
{
data: QRqueryData,
mode: 'byte',
},
// { data: '0123456', mode: 'numeric' },
]
let codeUrl = ''
QRCode.toDataURL(segs, function (err, url) {
codeUrl = url
console.log(err, 'err')
})
const qrCodeDom = document.getElementById('qrcode')
qrCodeDom.src = codeUrl
},
log太多懒得删,o(╥﹏╥)o大家将就看