Having Trouble with QR Code Generator Functionality

UPDATE: The initial code has been updated to implement the recommendations provided.

I am currently working on a QR Code generator that updates every minute. Although I have developed the code below, I am encountering some errors and could use some assistance completing this task.

<script>
import { useQRCode } from '@vueuse/integrations/useQRCode'
import { ref } from 'vue'

export default {
  name: 'QRCode Generator',
  data() {
    return {
      custID: ref('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="34574147405b595146745159555d581a575b59">[email protected]</a>'),
      getNow: ref(Date.now()),
      text: `${this.custID}?${this.getNow}`
    }
  },
  created() {
    setInterval(this.setQR, 3000)
  },
  methods: {
    getQR() {
      useQRCode(this.text)
    },
    setQR() {
      this.getNow = ref(Date.now())
    }
  }
}
</script>

<template>
  <input id="text" v-model="text" type="text" />
  <img :src="getQR" alt="QR Code" />
</template>

<style scoped></style>

My current issue is that I am getting undefined?undefined for my QRCode string, which may be due to incorrect callouts and undefined data.

The expected functionality involves generating a dynamic custID based on customer information (commonly an email address), while the getNow variable represents a timestamp used to modify the data fed into the Barcode Generator every minute. Note that the interval is set at 3 seconds for immediate observation purposes...

The values of custID and getNow are concatenated in the text variable before being passed to the QRCode generator to update the displayed content, utilizing a ? separator.

Despite experimenting with advice from various sources like StackOverflow, Google, and VueSchool, I haven't achieved a solution yet.

This problem has consumed a considerable amount of time, and I am seeking guidance to finalize the implementation.

Answer ā„–1

I made revisions to the code, now utilizing only the composition API instead of a combination of options and composition

<script setup>
import {ref, computed} from 'vue'
import { useQRCode } from '@vueuse/integrations/useQRCode'

const custID = ref('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f7c6a6c6b70727a6d5f7a727e7673317c7072">[email protected]</a>');
const date = ref(Date.now());

const text = computed(() => `${custID.value}?${date.value}`);
const qrcode = useQRCode(text);
</script>

<template>
  <div style="display: flex; flex-direction: column;">
    <input v-model="custID" type="text">
    <input v-model="date" type="number">
    <span>{{text}}</span>
  </div>
  <img :src="qrcode" alt="QR Code">
</template>

This example demonstrates reactivity with inputs for both date and custID. However, these values can be dynamically set within function component logic rather than just through input fields.

Answer ā„–2

I made some adjustments to your code structure by transitioning to the composition API and implementing a computed property for your text. Additionally, I included a cleanup process for the setInterval function when the component is no longer in use.

There were a few issues that could be resolved more efficiently using refs, so I switched those out. The main issue was ensuring that the useQRCode() function is called just once and provided with a dynamically updating ref or computed value for image changes.

<script setup>

import {useQRCode} from "@vueuse/integrations/useQRCode"
import {tryOnUnmounted} from "@vueuse/core"
import {computed, ref} from "vue"

const custID = ref('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d7c1c7c0dbd9d1c6f4d1d9d5ddd89ad7dbd9">[email protected]</a>')
const getNow = ref(Date.now())

const text = computed(() => {
  return `${custID.value}?${getNow.value}`
})

const qrCode = useQRCode(text)

function setNow() {
  getNow.value = Date.now()
}

let intervalId = setInterval(setNow, 10000)

tryOnUnmounted(() => {
  if (intervalId) {
    clearInterval(intervalId)
    intervalId = null
  }
})

</script>

<template>
  <input id="text" v-model="text" type="text" />
  <img :src="qrCode" alt="QR Code" />
</template>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ms-card malfunctioning due to data issues

I'm facing difficulties in transferring the data to the template. Although I can access the data in HTML using vm.maquinas and maquina, I am unable to pass it to the TEMPLATE through ng-model. Information about ms-cards was not abundant. Module ang ...

A simple method for bulk editing in Angular UI Grid

Is there a way to enable mass editing in Angular UI Grid by allowing all rows to show editable input fields at once, rather than just one at a time? I have searched online for a solution without success and am now turning to this forum for help. If anyone ...

Is it possible to adjust the range of a range slider based on the selection of a radio button or other input method?

I have a query and Iā€™m hopeful you can assist: function UpdateTemperature() { var selectedGrade = $( "input[name='radios']:checked" ).val(); $( ".c_f" ).text(selectedGrade); var value1 = $("#tempMin").val(); var value2 = $("#tempM ...

Assign the private members of the class to the arguments of the constructor

class Bar { #one #two #three #four #five #six #seven #eight #nine #ten #eleven #twelve #thirteen #fourteen #fifteen #sixteen constructor( one, two, three, four, five, six, seven, eight, ...

Extremely sluggish change identification in combination Angular application

We are encountering consistent issues with slow change detection in our hybrid AngularJS / Angular 8 app, especially when dealing with components from different versions of the framework. The problem seems to arise when using older AngularJS components wit ...

What is the best way to refresh the parent div of a component in vue.js?

Have you ever wondered if it's possible to achieve this code snippet: <div v-for="tile in container" v-bind:class="proper-class"> <tile :tile='tile' @update="update-class"></tile> </div> The goal is to change th ...

Using AngularJS to compare values against user input to determine if they are greater or lesser

When a user inputs data into an input field, it must fall within the range of values retrieved from the database. The value entered by the user should meet either the minimum, maximum, or default value obtained from the database. For instance, if the minim ...

Trouble with Bootstrap modal implementation when using ajax and looping through data

I am having an issue with using the BS modal to display a form containing a select box and updating records in the database via an ajax call. The trigger button to open the modal consists of <i></i> tags with the same class name, itagbtn, and d ...

Issue: Error encountered while trying to use the removeAttribute() function in Selenium and Java: missing closing parenthesis after argument list

WebElement removeReadOnly=driver.findElement(By.xpath("//input[@id='mat-input-0']")); js.executeScript("document.getElementBypath('//input[@id='mat-input-0']').removeAttribute('readonly');",&quo ...

Deciding whether an altered image has been successfully loaded

Currently, I am stuck on a minor point while creating a small gallery using jQuery. The code snippet looks like this: <script type="text/javascript> $(document).ready(function(){ $('#thumb1').click(function(){ $('#fullimage ...

Customizing Bootstrap Vue to prevent tooltips from opening on hover

I am currently using a tooltip similar to the example shown on Toggle Tooltip: <template> <div class="text-center"> <div> <b-button id="tooltip-button-1" variant="primary">I have a tooltip</b-button> </div& ...

What is the best way to update the value of the nearest input field?

I am working with a table that has multiple rows, all structured in the same way. I have created a DIV element that can be clicked. When a user clicks on the DIV, I want the value of the input field in the same row to change. However, with the current co ...

Setting default values in select options in Vue3

Is there a way to set a default value for this template? I want the default value to be 'Please Select...', which is the first option in the list. <template #dropDownSelection="{ props }"> <td colspan="1"> ...

Items seem to vanish into thin air and become immovable when attempting to relocate them

I am attempting to create a unique grid layout with 3x3 dimensions, where each grid item represents a fragment of a single image. These items should have the capability to be dragged and dropped inside another 3x3 grid, in any desired sequence. I have hit ...

Obtaining the parent template component in Vue: A quick guide

When using Vue, I am aware that this.$parent can be used to access the upper component in the vdom tree. However, what I am looking for is a way to access the specific component that rendered the current one. For example, let's say I have a component ...

Protractor sendKeys method on Modal dialog is failing due to element visibility issues

I seem to be facing a strange issue with protractor. My challenge lies in testing a form that is situated within a modal. Although I am able to verify that the modal is indeed open, I encounter difficulties when attempting to sendKeys to the input fields. ...

Verifying user login on NodeJS through connection from an IIS-hosted website

I am currently upgrading an outdated CMS system and looking to implement a real-time chat feature. The existing CMS operates on IIS, MSSQL, and PHP. The chat feature will be hosted on a separate Linux box running Node.js and Socket.io After successfully ...

I am a newcomer to HTML and I am eager to display the selected options from a <select> element

Can someone help me display the selected licorice flavor, chocolate color, and topping? For example: "Green apple, white, christmas sprinkles." I'm not sure if assigning a numeric value to each option is necessary. I did it on a whim. Please suggest ...

Clearing AsyncStorage in React Native

It has come to my attention that I am spending a significant amount of time debugging redux actions in react-native that are being persisted to AsyncStorage using redux-persist. There are instances where I wish I could simply clear AsyncStorage in order to ...

Topaz font does not properly display backslashes and certain characters when rendered on Canvas

Who would have thought I'd stumble upon a new challenge on Stack Overflow? But here we are. If there's already a solution out there, please guide me in the right direction. I'm currently developing an interactive desktop environment inspired ...