qrCode生成二维码内容

1、二维码页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二维码页面</title>
    <script src="qrcode.min.js"></script>
</head>
<body>
<div id="qrCode"></div>
</body>
<script>
        var testQrCode = new QRCode("qrCode", {
   
            text: "content.html",   // 二维码扫描内容页面
            width: 128,
            height: 128,
            colorDark : "#000000",  // 码的颜色
            colorLight : "#ffffff",  // 码的背景色
            correctLevel : QRCode.CorrectLevel.H  // 高度容错
        });
    // }
</script>
</html>

2、二维码扫描出的内容写在content.html里面,比如:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>内容</title>
</head>
<body>
<div>扫描出的内容</div>
</body>
</html>

3、引入的js文件

var QRCode;!function(){
   function a(a){
   this.mode=c.MODE_8BIT_BYTE,this.data=a,this.parsedData=[];for(var b=[],d=0,e=this.data.length;e>d;d++){
   var f=this.data.charCodeAt(d);f>65536?(b[0]=240|(1835008&f)>>>18,b[1]=128|(258048&f)>>>12,b[2]=128|(4032&f)>>>6,b[3]=128|63&f):f>2048?(b[0]=224|(61440&f)>>>12,b[1]=128|(4032&f)>>>6,b[2]=128|63&f):f>128?(b[0]=192|(1984&f)>>>6,b[1]=128|63&f):b[0]=f,this.parsedData=this.parsedData.concat(b)}this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function b(a,b){
   this.typeNumber=a,this.errorCorrectLevel=b,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function i(a,b){
   if(void 0==a.length)throw new Error(a.length+"/"+b);for(var c=0;c<a.length&&0==a[c];)c++;this.num=new Array(a.length-c+b);for(var d=0;d<a.length-c;d++)this.num[d]=a[d+c]}function j(a,b){
   this.totalCount=a,this.dataCount=b}function k(){
   this.buffer=[],this.length=0}function m(){
   return"undefined"!=typeof CanvasRenderingContext2D}function n(){
   var a=!1,b=navigator.userAgent;return/android/i.test(b)&&(a=!0,aMat=b.toString().match(/android ([0-9]\.[0-9])/i),aMat&&aMat[1]&&(a=parseFloat(aMat[1]))),a}function r(a,b){
   for(var c=1,e=s(a),f=0,g=l.length;g>=f;f++){
   var h=0;switch(b){
   case d.L:h=l[f][0];break;case d.M:h=l[f][1];break;case d.Q:h=l[f][2];break;case d.H:h=l[f][3]}if(h>=e)break;c++}if(c>l.length)throw new Error("Too long data");return c}function s(a){
   var b=encodeURI(a).toString().replace(/\%[0-9a-fA-F]{
   2}/g,"a");return b.length+(b.length!=a?3:0)}a.prototype={
   getLength:function(){
   return this.parsedData.length},write:function(a){
   for(var b=0,c=this.parsedData.length;c>b;b++)a.put(this.parsedData[b],8)}},b.prototype={
   addData:function(b){
   var c=new a(b);this.dataList.push(c),this.dataCache=null},isDark:function(a,b){
   if(0>a||this.moduleCount<=a||0>b||this.moduleCount<=b)throw new Error(a+","+b);return this.modules[a][b]},getModuleCount:function(){
   return this.moduleCount},make:function(){
   this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(a,c){
   this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var d=0;d<this.moduleCount;d++){
   this.modules[d]=new Array(this.moduleCount);for(var e=0;e<this.moduleCount;e++)this.modules[d][e]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(a,c),this.typeNumber>=7&&this.setupTypeNumber(a),null==this.dataCache&&(this.dataCache=b.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,b){
   for(var c=-1;7>=c;c++)if(!(-1>=a+c||this.moduleCount<=a+c))for(var d=-1;7>=d;d++)-1>=b+d||this.moduleCount<=b+d||(this.modules[a+c][b+d]=c>=0&&6>=c&&(0==d||6==d)||d>=0&&6>=d&&(0==c||6==c)||c>=2&&4>=c&&d>=2&&4>=d?!0:!1)},getBestMaskPattern:function(){
   for(var a=0,b=0,c=0;8>c;c++){
   this.makeImpl(!0,c);var d=f.getLostPoint(this);(0==c||a>d)&&(a=d,b=c)}return b},createMovieClip:function(a,b,c){
   var d=a.createEmptyMovieClip(b,c),e=1;this.make();for(v
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue中使用qrcode生成二维码,你可以按照以下步骤进行操作: 1. 首先,你需要安装qrcode插件,你可以使用npm命令来安装:npm i qrcode -S 。 2. 然后,在你的Vue组件中引入qrcode插件:import QRCode from 'qrcode' 。 3. 接下来,在你的Vue组件的template中添加一个img标签,用于显示生成的二维码图片。例如: ``` <template> <div> <img :src="QRImgUrl" /> </div> </template> ``` 4. 在Vue组件的script中,使用QRCode生成二维码的方法。首先,你需要定义一个data属性QRImgUrl用于存储生成的二维码图片的URL。然后,在created钩子函数中调用getQRcode方法来生成二维码。getQRcode方法使用QRCode.toDataURL来生成二维码图片的DataURL,并将生成的URL赋值给QRImgUrl。例如: ``` <script> import QRCode from 'qrcode' export default { data() { return { QRImgUrl: '', QRlink:'www.xxx.com' } }, created() { this.getQRcode() }, methods: { getQRcode(){ QRCode.toDataURL(this.QRlink, { errorCorrectionLevel: 'L', margin: 2, width: 128 }, (err, url) => { if (err) throw err this.QRImgUrl = url }) } } } </script> ``` 这样,当你的Vue组件被创建时,getQRcode方法会被调用,生成二维码并将URL赋值给QRImgUrl,从而显示在页面上 。 如果你想对生成的二维码进行更详细的配置,你可以参考以下步骤: 1. 在getQRcode方法中定义一个opts对象,用于配置生成二维码的各种参数,比如容错级别、二维码类型、二维码质量、留白边距等 。 2. 修改QRCode.toDataURL方法的第二个参数为opts,这样可以根据opts的配置生成更加符合你需求的二维码 。 例如,你可以按照以下方式配置opts对象: ```javascript let opts = { errorCorrectionLevel: "L",//容错级别 type: "image/png",//生成的二维码类型 quality: 0.3,//二维码质量 margin: 5,//二维码留白边距 width: 128,//宽 height: 128,//高 text: "http://www.xxx.com",//二维码内容 color: { dark: "#666666",//前景色 light: "#fff"//背景色 } }; ``` 然后,将opts作为QRCode.toDataURL方法的第二个参数传入: ```javascript QRCode.toDataURL(this.QRlink, opts, (err, url) => { if (err) throw err this.QRImgUrl = url }) ``` 这样,你就可以根据opts的配置生成定制化的二维码 。 综上所述,你可以按照以上步骤在Vue中使用qrcode生成二维码,并根据需要进行详细的配置 。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值