Vue實(shí)現(xiàn)手機(jī)掃描二維碼預(yù)覽頁面效果
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)手機(jī)掃描二維碼預(yù)覽頁面的具體代碼,供大家參考,具體內(nèi)容如下
背景:vue-cli3 + ant-design-vue 搭建的后臺(tái)管理系統(tǒng)
需求:實(shí)現(xiàn)掃描二維碼即可在手機(jī)預(yù)覽H5頁面功能
使用插件: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>
更多文章可以點(diǎn)擊《Vue.js前端組件學(xué)習(xí)教程》學(xué)習(xí)閱讀。
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請(qǐng)閱讀專題《vue實(shí)戰(zhàn)教程》
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
如何在Vue中使用CleaveJS格式化你的輸入內(nèi)容
這篇文章主要介紹了如何在Vue中使用CleaveJS格式化你的輸入內(nèi)容,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12vue實(shí)現(xiàn)垂直無限滑動(dòng)日歷組件
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)垂直無限滑動(dòng)日歷組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04vue中實(shí)現(xiàn)一個(gè)項(xiàng)目里兼容移動(dòng)端和pc端
這篇文章主要介紹了vue中實(shí)現(xiàn)一個(gè)項(xiàng)目里兼容移動(dòng)端和pc端問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12