From b21de261c3940a6314c3e1ec1c2a76992e834f72 Mon Sep 17 00:00:00 2001 From: Adam Procter <adamprocter@researchnot.es> Date: Mon, 10 Feb 2020 20:53:12 +0000 Subject: [PATCH] migrated data to store --- canvas-10-feb/src/components/HelloWorld.vue | 26 ++++++--------------- canvas-10-feb/src/store/index.js | 17 +++++++++++++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/canvas-10-feb/src/components/HelloWorld.vue b/canvas-10-feb/src/components/HelloWorld.vue index 191f1c9..8743f80 100644 --- a/canvas-10-feb/src/components/HelloWorld.vue +++ b/canvas-10-feb/src/components/HelloWorld.vue @@ -20,6 +20,7 @@ </template> <script> +import { mapState } from 'vuex' var canvas = null export default { @@ -27,24 +28,12 @@ export default { props: { msg: String }, - data: function() { - return { - configRect: { - x: -25, - y: -25, - height: 50, - width: 50, - fill: 'rgb(200, 0, 0)' - }, - configHandle: { - x: 25, - y: 25, - height: 4, - width: 4, - fill: 'black' - } - } - }, + + computed: mapState({ + configRect: state => state.configRect, + configHandle: state => state.configHandle + }), + mounted() { canvas = this.$refs.canvas this.ctx = canvas.getContext('2d') @@ -53,7 +42,6 @@ export default { methods: { draw() { this.box(this.ctx, this.x, this.y) - console.log('draw') }, box(ctx, x, y) { diff --git a/canvas-10-feb/src/store/index.js b/canvas-10-feb/src/store/index.js index 0107c20..badaf8c 100644 --- a/canvas-10-feb/src/store/index.js +++ b/canvas-10-feb/src/store/index.js @@ -4,7 +4,22 @@ import Vuex from 'vuex' Vue.use(Vuex) export default new Vuex.Store({ - state: {}, + state: { + configRect: { + x: -25, + y: -25, + height: 50, + width: 50, + fill: 'rgb(200, 0, 0)' + }, + configHandle: { + x: 25, + y: 25, + height: 4, + width: 4, + fill: 'black' + } + }, mutations: {}, actions: {}, modules: {} -- GitLab