Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onscan js with VueJS #29

Open
kunalchawla2401 opened this issue Aug 2, 2021 · 1 comment
Open

onscan js with VueJS #29

kunalchawla2401 opened this issue Aug 2, 2021 · 1 comment

Comments

@kunalchawla2401
Copy link

Hi I am using vuejs for my application and need to integrate onscan js with that. I ma facing below issues -

  1. I added onscanjs under main.js and import it so that I can use it anywhere in the whole application.
  2. Once, I go to my components, it doesn't find onscan js at all. So I removed it from main.js and imported it under every componenet where its needed.
  3. Now, it is trying to mount onscan every time a scan is done which is giving me console errors and the scan works for the first time only (when there is no console error)
    Please help
@dragospeta
Copy link

I added it yesterday and works fine
in main.js:
import onScan from 'onscan.js';
onScan.attachTo(window); // add second argument of options if you need

Then in components use:
mounted() {
window.addEventListener('scan', this.handlePaste);
},
destroyed() {
window.removeEventListener('scan', this.handlePaste);
},
where this.handlePaste is a method that receives an event as parameter.

Depends on the application, you can put the mounted/destroyed functionality in a parent component and communicate through events/bus without needing to write it in multiple children components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants