Vue實現(xiàn)手機(jī)掃描二維碼預(yù)覽頁面效果
本文實例為大家分享了Vue實現(xiàn)手機(jī)掃描二維碼預(yù)覽頁面的具體代碼,供大家參考,具體內(nèi)容如下
背景:vue-cli3 + ant-design-vue 搭建的后臺管理系統(tǒng)
需求:實現(xiàn)掃描二維碼即可在手機(jī)預(yù)覽H5頁面功能
使用插件:qrcode
step1:安裝插件
npm install qrcode --save
step2:引入插件
在項目中新建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>
更多文章可以點擊《Vue.js前端組件學(xué)習(xí)教程》學(xué)習(xí)閱讀。
關(guān)于vue.js組件的教程,請大家點擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請閱讀專題《vue實戰(zhàn)教程》
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
如何在Vue中使用CleaveJS格式化你的輸入內(nèi)容
這篇文章主要介紹了如何在Vue中使用CleaveJS格式化你的輸入內(nèi)容,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12