GithubHelp home page GithubHelp logo

How to use it in vue about html5-qrcode HOT 7 CLOSED

mebjas avatar mebjas commented on May 15, 2024
How to use it in vue

from html5-qrcode.

Comments (7)

lintiansheng avatar lintiansheng commented on May 15, 2024 1

thank your very much,I used the CDN import to solve it。

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024 1

I recently made an update to the library which makes integration much easier with complete user interface to the scanner. The new class included in the library is called Html5QrcodeScanner

This makes the VueJs component much simpler as well. - Just following lines*

Vue.component('qrcode-scanner', {
	props: {
		qrbox: Number,
		fps: Number,
	},
	template: `<div id="qr-code-full-region"></div>`,
	mounted: function () {
		var config = { fps: this.fps ? this.fps : 10 };
		if (this.qrbox) {
			config['qrbox'] = this.qrbox;
		}

		function onScanSuccess(qrCodeMessage) {
			console.log(qrCodeMessage);
		}
		
		var html5QrcodeScanner = new Html5QrcodeScanner(
			"qr-code-full-region", config);
		html5QrcodeScanner.render(onScanSuccess);
	}
});

You may have to update onScanSuccess and bind it directly with the some component callback - I am sure there are ways to do it - I am just not aware of it.

Using it in html is the same

<qrcode-scanner 
    v-bind:qrbox="250" 
    v-bind:fps="10"
    style="width: 500px;">
</qrcode-scanner>

Updated demo code here as well - https://github.com/mebjas/html5-qrcode-examples/tree/master/vuejs

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024

I assume this is copy of #48.

I have not worked with vue before but I assume there is an import error. I'll play around and see how to do it and get back.

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024

Meanwhile it'd be nice if you could share screenshot or error message here - I am closing the other one as duplicate for now.

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024

@lintiansheng I have not used vue js before and I went through the basic tutorials to come up with working example

I have defined a component in this js file: https://github.com/mebjas/html5-qrcode-examples/blob/master/vuejs/vuejs/main.js

Vue.component('qrcode-scanner', {
	props: {
		qrBox: Number,
	},
        // rest of things ... refer the link to js file 

and the set the component in html like

<qrcode-scanner v-bind:qrBox="250" style="width: 500px;"></qrcode-scanner>

The demo looks like this
image

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024

I am sure this is a hacky way to do this, I'll read more about vue and try to implement a proper component

from html5-qrcode.

mebjas avatar mebjas commented on May 15, 2024

Closing this issue!

from html5-qrcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.