我是靠谱客的博主 动听毛豆,这篇文章主要介绍Vue实现手机扫描二维码预览页面效果,现在分享给大家,希望可以做个参考。

本文实例为大家分享了Vue实现手机扫描二维码预览页面的具体代码,供大家参考,具体内容如下

背景:vue-cli3 + ant-design-vue 搭建的后台管理系统
需求:实现扫描二维码即可在手机预览H5页面功能

使用插件:qrcode

step1:安装插件

复制代码
1
npm install qrcode --save

step2:引入插件

在项目中新建QRcode.vue文件

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<template> <div id="qrCode"> <div id="code"></div> <canvas id="canvas"></canvas> </div> </template> <script> import QRCode from "qrcode"; export default { props: { url: { type: String } }, data() { return { msg: "hello vue", codes: "" }; }, components: { QRCode: QRCode }, methods: { useqrcode() { var canvas = document.getElementById("canvas"); QRCode.toCanvas(canvas, this.url, function(error) { if (error) console.error(error); }); } }, mounted() { this.useqrcode(); } }; </script> <style lang="stylus" scoped> #qrCode { text-align: center; } </style>

step3:在需要使用该插件的地方引入

例如:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<template> <div> <QRcode :url='url'/> </div> </template> <script> import QRcode from '../../QRcode.vue' export default { components: { QRcode }, data() { return { url:'(需要生成二维码的网址)' } } } </script>

更多文章可以点击《Vue.js前端组件学习教程》学习阅读。

关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。

更多vue学习教程请阅读专题《vue实战教程》

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是动听毛豆最近收集整理的关于Vue实现手机扫描二维码预览页面效果的全部内容,更多相关Vue实现手机扫描二维码预览页面效果内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(133)

评论列表共有 0 条评论

立即
投稿
返回
顶部