您好,登錄后才能下訂單哦!
這篇文章主要講解了Vue中手機(jī)掃描二維碼預(yù)覽頁(yè)面的實(shí)現(xiàn)方法,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
背景:vue-cli3 + ant-design-vue 搭建的后臺(tái)管理系統(tǒng)
需求:實(shí)現(xiàn)掃描二維碼即可在手機(jī)預(yù)覽H5頁(yè)面功能
使用插件:qrcode
step1:安裝插件
npm install qrcode --save
step2:引入插件
在項(xiàng)目中新建QRcode.vue文件
<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:在需要使用該插件的地方引入
例如:
<template> <div> <QRcode :url='url'/> </div> </template> <script> import QRcode from '../../QRcode.vue' export default { components: { QRcode }, data() { return { url:'(需要生成二維碼的網(wǎng)址)' } } } </script>
看完上述內(nèi)容,是不是對(duì)Vue中手機(jī)掃描二維碼預(yù)覽頁(yè)面的實(shí)現(xiàn)方法有進(jìn)一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。