Vue QR

repository·master·Indexed 21 days ago

https://github.com/binaryify/vue-qr

Searchable repository documentation for Binaryify Vue Qr from https://github.com/binaryify/vue-qr.

Tokens
2K
Snippets
11
Records
12
Agent score
72%

What's inside binaryify/vue-qr

  1. Register vue-qr globally

    master

    To make the VueQr component available throughout your entire Vue 3 application, use the install function during app initialization.

    import { createApp } from 'vue'
    import { VueQr, install } from 'vue-qr'
    
    const app = createApp(App)
    app.use({ install }) // or app.component('VueQr', VueQr)
    app.mount('#app')
  2. Register vue-qr locally

    master

    To use the component only within a specific Vue component, import VueQr directly in your <script setup> block.

    <script setup>
    import VueQr from 'vue-qr'
    </script>
    
    <template>
      <vue-qr text="Hello world!" />
    </template>
  3. Customize component parts with ComponentOptions

    master

    The components prop allows for fine-grained control over the scale and protector settings of different parts of the QR code. This follows the structure of Awesome-qr.js.

    Available keys in the components object:

    • data: Controls data dots.
    • timing: Controls timing patterns.
    • alignment: Controls alignment patterns.
    • cornerAlignment: Controls corner alignment patterns.

    Each key accepts an object with scale (number) and protectors (boolean).

    type ComponentOptions = {
      data?: { scale?: number }
      timing?: { scale?: number; protectors?: boolean }
      alignment?: { scale?: number; protectors?: boolean }
      cornerAlignment?: { scale?: number; protectors?: boolean }
    }
  4. Install vue-qr as a Vue plugin

    master

    To use vue-qr globally in your Vue application, use the install function. This registers the VueQr component so it can be used in any template without local registration.

    import { install } from 'vue-qr';
    
    // In your main.js or app entry point
    const app = createApp(App);
    app.use(install);
  5. Install VueQr globally in a Vue application

    master

    You can register VueQr globally using the install method. This makes the component available throughout your entire Vue application without needing to import it in every file.

    import { createApp } from 'vue';
    import VueQr from 'vue-qr';
    import App from './App.vue';
    
    const app = createApp(App);
    
    // Global registration
    app.use(VueQr);
    
    app.mount('#app');
    import { createApp } from 'vue';
    import VueQr from 'vue-qr';
    import App from './App.vue';
    
    const app = createApp(App);
    app.use(VueQr);
    app.mount('#app');
  6. Handle the generated event

    master

    The generated event is emitted when the QR code has been successfully created. It provides the dataUrl of the generated image and the qid (if provided).

    <script setup>
    function onGenerated(dataUrl, id) {
      console.log(dataUrl, id)
    }
    </script>
    
    <template>
      <vue-qr text="Hello world!" @generated="onGenerated" qid="testid" />
    </template>
  7. Fine-tune component scaling with ComponentOptions

    master

    The components prop allows you to adjust the scale of specific QR code elements. Each sub-option can specify a scale and whether protectors should be applied.

    Supported keys within ComponentOptions:

    • data: Controls the scale of the data modules.
    • timing: Controls the scale of the timing patterns.
    • alignment: Controls the scale of the alignment patterns.
    • cornerAlignment: Controls the scale of the corner alignment patterns.
    const componentConfig = {
      data: { scale: 1.2 },
      timing: { scale: 1.0, protectors: true },
      alignment: { scale: 1.1, protectors: true },
      cornerAlignment: { scale: 1.0, protectors: true }
    };
    
    // Usage in component
    <VueQr text="..." :components="componentConfig" />
  8. Configure vue-qr with Props

    master

    The vue-qr component accepts several props to customize the appearance, content, and behavior of the QR code.

    Required Props:

    • text: The string content to encode in the QR code.

    Key Configuration Props:

    • size: Width and height of the output (includes margin). Default: 200.
    • margin: Margin around the QR code. Default: 20.
    • colorDark: Color of data blocks. Default: '#000000'.
    • colorLight: Color of empty space. Default: '#FFFFFF'.
    • bgSrc: Background image URL.
    • gifBgSrc: GIF background URL (overrides bgSrc).
    • logoSrc: URL for the logo at the center.
    • logoScale: Scale factor for the logo relative to the QR size. Default: 0.2.
    • autoColor: If true, uses the dominant color of the background as colorDark. Default: true.
    • qid: A unique string ID used for async identification in the generated event.
  9. Configure VueQr component props

    master

    The VueQrProps interface defines the configuration for the QR code generator. Key properties include:

    • text: (Required) The string content to encode in the QR code.
    • qid: An optional unique identifier for the QR code.
    • size: The dimensions of the QR code.
    • margin: The margin around the QR code.
    • colorDark: The color of the dark modules (default is usually black).
    • colorLight: The color of the light modules.
    • bgSrc / background / backgroundDimming: Options for setting the background image or color.
    • logoSrc: The source URL/path for a logo to be placed in the center.
    • logoScale: The scale of the logo.
    • logoMargin: The margin for the logo.
    • logoCornerRadius: The corner radius for the logo.
    • dotScale: The scale of the dots.
    • binarize: Whether to apply binarization.
    • components: An object to fine-tune the scaling of specific parts like data, timing, alignment, or cornerAlignment.
    // Example usage of props
    <VueQr 
      text="https://example.com" 
      size="200" 
      colorDark="#000000" 
      logoSrc="/path/to/logo.png" 
      logoScale="0.2"
    />
  10. Handle the 'generated' event in VueQr

    master

    The VueQr component emits a generated event when the QR code has been successfully rendered. This event provides the resulting data URL, which can be used to display the image elsewhere or download it.

    Arguments:

    • dataUrl: (string) The base64 encoded data URL of the generated QR code.
    • qid: (string, optional) The unique identifier passed to the component.
    // Example event handling
    <VueQr 
      text="hello" 
      @generated="onGenerated" 
    />
    
    // In your script
    const onGenerated = (dataUrl: string, qid?: string) => {
      console.log('QR Code Data URL:', dataUrl);
    };