1.安裝
npm install qrcode-decoder
2.elementUI上傳插件
<template>
<el-upload
action=""
:show-file-list="false"
:http-request="resolveQR"
>
<el-button
type="success"
>上傳</el-button>
</el-upload>
</template>
3.js部分
methods: {
resolveQR(event) {
const url = window.webkitURL.createObjectURL(event.file);
const qr = new QrCode();
const result = qr.decodeFromImage(url);
result
.then(res => {
if (res.data) {
console.log(res.data);//得到解析出來的字符串
this.$message.success("識別二維碼成功!");
} else {
//console.log(res);
this.$message.error("識別二維碼失敗, 請重新上傳");
}
})
.catch(err => {
this.$message.error(JSON.stringify(err));
});
}
}