main.ts
1 2 3 4 5 6 7 8 9 10 11 12 |
import { createApp } from "vue"; import "./style.css"; import App from "./App.vue"; import VueQrcode from '@chenfengyuan/vue-qrcode'; const app = createApp(App); app.component(VueQrcode.name, VueQrcode); // Mount the app app.mount("#app"); |
App.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 45 46 47 48 49 50 51 52 53 54 55 56 |
<template> <vue-qrcode value="https://freemediatools.com" :options="{ errorCorrectionLevel: 'Q', width: 200, color: { dark: '#0074d9', light: '#7fdbff', }, }" @ready="onReady" ></vue-qrcode> </template> <script> export default { methods: { onReady(canvas) { const context = canvas.getContext('2d'); const image = new Image(); image.src = 'https://avatars.githubusercontent.com/u/3456749'; image.crossorigin = 'anonymous'; image.onload = () => { const coverage = 0.15; const width = Math.round(canvas.width * coverage); const x = (canvas.width - width) / 2; this.drawImage(context, image, x, x, width, width); }; }, drawImage(context, image, x, y, width, height, radius = 4) { context.shadowOffsetX = 0; context.shadowOffsetY = 2; context.shadowBlur = 4; context.shadowColor = '#00000040'; context.lineWidth = 8; context.beginPath(); context.moveTo(x + radius, y); context.arcTo(x + width, y, x + width, y + height, radius); context.arcTo(x + width, y + height, x, y + height, radius); context.arcTo(x, y + height, x, y, radius); context.arcTo(x, y, x + width, y, radius); context.closePath(); context.strokeStyle = '#fff'; context.stroke(); context.clip(); context.fillStyle = '#fff'; context.fillRect(x, x, width, height); context.drawImage(image, x, x, width, height); }, }, } </script> |
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 45 46 47 48 49 50 51 52 53 54 55 56 |
<template> <vue-qrcode value="https://freemediatools.com" :options="{ errorCorrectionLevel: 'Q', width: 200, color: { dark: '#0074d9', light: '#7fdbff', }, }" @ready="onReady" ></vue-qrcode> </template> <script> export default { methods: { onReady(canvas) { const context = canvas.getContext('2d'); const image = new Image(); image.src = 'https://avatars.githubusercontent.com/u/3456749'; image.crossorigin = 'anonymous'; image.onload = () => { const coverage = 0.15; const width = Math.round(canvas.width * coverage); const x = (canvas.width - width) / 2; this.drawImage(context, image, x, x, width, width); }; }, drawImage(context, image, x, y, width, height, radius = 4) { context.shadowOffsetX = 0; context.shadowOffsetY = 2; context.shadowBlur = 4; context.shadowColor = '#00000040'; context.lineWidth = 8; context.beginPath(); context.moveTo(x + radius, y); context.arcTo(x + width, y, x + width, y + height, radius); context.arcTo(x + width, y + height, x, y + height, radius); context.arcTo(x, y + height, x, y, radius); context.arcTo(x, y, x + width, y, radius); context.closePath(); context.strokeStyle = '#fff'; context.stroke(); context.clip(); context.fillStyle = '#fff'; context.fillRect(x, x, width, height); context.drawImage(image, x, x, width, height); }, }, } </script> |