Skip to content

Commit

Permalink
Vuejs 2 support added
Browse files Browse the repository at this point in the history
  • Loading branch information
smronju committed Oct 10, 2016
1 parent 26218f2 commit 0993e75
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 50 deletions.
32 changes: 17 additions & 15 deletions VueWebcam.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
const Vue = require('vue');

const WebcamComponent = Vue.extend({
render: function (h) {
return h('video', {
ref: 'video',
attrs: {
width: this.width,
height: this.height,
src: this.src,
autoplay: this.autoplay,
style: this.styleObject
}
});
},
props: {
autoplay: {
type: Boolean,
Expand All @@ -23,16 +35,6 @@ const WebcamComponent = Vue.extend({
default: 'image/jpeg'
}
},
template: `
<video
v-el:video
:width="width"
:height="height"
:src="src"
:autoplay="autoplay"
:style="styleObject"
></video>
`,
data () {
return {
video: '',
Expand All @@ -55,7 +57,7 @@ const WebcamComponent = Vue.extend({
getCanvas () {
if (!this.hasUserMedia) return null;

const video = this.$els.video;
const video = this.$refs.video;
if (!this.ctx) {
const canvas = document.createElement('canvas');
canvas.height = video.clientHeight;
Expand All @@ -79,8 +81,8 @@ const WebcamComponent = Vue.extend({
}

},
ready () {
this.video = this.$els.video;
mounted: function () {
this.video = this.$refs.video;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;

if (navigator.getUserMedia) {
Expand All @@ -93,12 +95,12 @@ const WebcamComponent = Vue.extend({
});
}
},
beforeDestroy () {
beforeDestroy: function () {
this.video.pause();
this.src = '';
this.stream.getTracks()[0].stop();
},
destroyed () {
destroyed: function () {
console.log('Destroyed');
}
});
Expand Down
6 changes: 3 additions & 3 deletions example/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": ["es2015", "stage-2"],
"plugins": ["transform-runtime"],
"comments": false
"presets": [
["es2015", { "modules": false }]
]
}
4 changes: 2 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# vue-cropperjs-example

> Example project for vue-webcam component.
> Example project for vue-webcam package
## Build Setup

``` bash
# install dependencies.
# install dependencies
npm install

# serve with hot reload at localhost:8080
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="stylesheet" href="style.css" />
</head>
<body>
<app></app>
<div id="app"></div>
<script src="dist/build.js"></script>
</body>
</html>
24 changes: 8 additions & 16 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,19 @@
"start": "webpack-dev-server --open --inline --hot"
},
"dependencies": {
"babel-runtime": "^6.0.0",
"vue": "^1.0.26",
"vue-webcam": "^1.0.0"
"vue": "^2.0.1",
"vue-webcam": "^2.0.2"
},
"devDependencies": {
"babel-core": "^6.0.0",
"babel-loader": "^6.0.0",
"babel-plugin-transform-runtime": "^6.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-2": "^6.0.0",
"cross-env": "^1.0.6",
"css-loader": "^0.23.1",
"file-loader": "^0.8.4",
"json-loader": "^0.5.4",
"cross-env": "^3.0.0",
"css-loader": "^0.25.0",
"file-loader": "^0.9.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.0.0",
"vue-loader": "^8.2.1",
"vue-style-loader": "^1.0.0",
"webpack": "^1.12.2",
"webpack-dev-server": "^1.12.0"
"vue-loader": "^9.4.0",
"webpack": "2.1.0-beta.22",
"webpack-dev-server": "^2.1.0-beta.0"
}
}
3 changes: 2 additions & 1 deletion example/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div id="app">
<vue-webcam v-ref:webcam></vue-webcam>
<vue-webcam ref='webcam'></vue-webcam>
<hr/>
<img :src="photo" alt="" style="width:400px;height:300px" />
<hr/>
Expand All @@ -12,6 +12,7 @@
import VueWebcam from 'vue-webcam';
export default {
name: 'App',
components: { VueWebcam },
data () {
return {
Expand Down
6 changes: 3 additions & 3 deletions example/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Vue from 'vue'
import App from './App.vue'

new Vue({
el: 'body',
components: { App }
})
el: '#app',
render: h => h(App)
});
10 changes: 3 additions & 7 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ module.exports = {
exclude: /node_modules/
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.html$/,
loader: 'vue-html'
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url',
loader: 'file',
query: {
limit: 10000,
name: '[name].[ext]?[hash]'
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-webcam",
"version": "1.0.0",
"version": "2.0.2",
"description": "A Vue component for capturing image from webcam.",
"main": "VueWebcam.js",
"keywords": [
Expand All @@ -21,6 +21,6 @@
},
"license": "MIT",
"peerDependencies": {
"vue": "^1.0.26"
"vue": ">=2.0.0"
}
}

0 comments on commit 0993e75

Please sign in to comment.