Skip to content
Snippets Groups Projects
Commit 875592d9 authored by Adam Procter's avatar Adam Procter
Browse files

Merge branch 'mixin'

parents 6cf0dae7 ea1de9c1
No related branches found
No related tags found
No related merge requests found
<template> <template>
<div class="hello"> <div class="hello">
<h1>{{ msg }}</h1> <h1>Welcome to Vue &amp; Canvas testing ground</h1>
<canvas ref="canvas"></canvas> <canvas ref="canvas"></canvas>
...@@ -21,13 +21,12 @@ ...@@ -21,13 +21,12 @@
<script> <script>
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { draw } from './mixins/draw.js'
var canvas = null var canvas = null
export default { export default {
name: 'HelloWorld', name: 'HelloWorld',
props: { mixins: [draw],
msg: String
},
computed: mapState({ computed: mapState({
configRect: state => state.configRect, configRect: state => state.configRect,
...@@ -40,33 +39,6 @@ export default { ...@@ -40,33 +39,6 @@ export default {
this.draw() this.draw()
}, },
methods: { methods: {
draw() {
this.box(this.ctx, this.x, this.y)
},
box(ctx, x, y) {
ctx.setTransform(1, 0, 0, 1, x, y)
ctx.fillStyle = this.configRect.fill
ctx.fillRect(
this.configRect.x,
this.configRect.y,
this.configRect.height,
this.configRect.width
)
ctx.fillStyle = this.configHandle.fill
ctx.fillRect(
this.configHandle.x,
this.configHandle.y,
this.configHandle.height,
this.configHandle.width
)
ctx.stroke()
ctx.setTransform(1, 0, 0, 1, 0, 0)
},
clear(ctx) { clear(ctx) {
ctx.clearRect(0, 0, canvas.width, canvas.height) ctx.clearRect(0, 0, canvas.width, canvas.height)
} }
......
export const draw = {
methods: {
draw() {
this.box(this.ctx, this.x, this.y)
},
box(ctx, x, y) {
ctx.setTransform(1, 0, 0, 1, x, y)
ctx.fillStyle = this.configRect.fill
ctx.fillRect(
this.configRect.x,
this.configRect.y,
this.configRect.height,
this.configRect.width
)
ctx.fillStyle = this.configHandle.fill
ctx.fillRect(
this.configHandle.x,
this.configHandle.y,
this.configHandle.height,
this.configHandle.width
)
ctx.stroke()
ctx.setTransform(1, 0, 0, 1, 0, 0)
}
}
}
<template> <template>
<div class="home"> <div class="home">
<HelloWorld msg="Welcome to Vue &amp; Canvas testing ground" /> <HelloWorld />
</div> </div>
</template> </template>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment