I have a unique QR code generator on my website. I would like the QR codes to be generated dynamically based on user input, but not instantly. Instead, I want to wait for the user to finish typing before generating the QR code after one second. Here is the template for my setup:
<div class="app">
<qrcode-vue :value="generatedQrCode"></qrcode-vue>
<input type="text" v-model="qrCodeInput" />
</div>
Below is the script I am using:
import QrcodeVue from 'qrcode.vue';
export default {
data() {
return {
generatedQrCode: '',
qrCodeInput: '',
isInputFunctionRunning: false
}
},
watch: {
async qrCodeInput() {
if (this.isInputFunctionRunning) {
return;
}
this.isInputFunctionRunning = true;
await new Promise(r => setTimeout(r, 1000));
this.generatedQrCode = this.qrCodeInput;
this.isInputFunctionRunning = false;
}
}
components: {
QrcodeVue,
},
}
However, it seems that the code is not functioning as intended. It is generating the QR code every second instead of waiting for the user to finish typing. My goal is to update the QR code only after the user has finished typing and one second has passed.