From 8a7e2a25b2a1ce457a2a4a6a5cea04e017e00fcb Mon Sep 17 00:00:00 2001
From: bartvdbraak <bartvdbraak@gmail.com>
Date: Tue, 4 Feb 2020 23:21:35 +0100
Subject: [PATCH] sync instead of emit for configdata

---
 src/components/ConfigSection.vue |  6 +-----
 src/components/MainContent.vue   | 20 +++++++++++++-------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/components/ConfigSection.vue b/src/components/ConfigSection.vue
index 9dceffd..26c169e 100644
--- a/src/components/ConfigSection.vue
+++ b/src/components/ConfigSection.vue
@@ -176,15 +176,11 @@ export default {
 			});
 		}
 	},
-	beforeRouteLeave (to, from, next) {
-		this.$emit('update',this.configData);
-		next()
-	},
 	created() {
 		this.setRemember()
 	},
 	watch: {
-		configFile: function () {
+		configFile() {
 			if (window.File && window.FileReader && window.FileList && window.Blob) {
 				this.readFile(this.configFile);
 			} else {
diff --git a/src/components/MainContent.vue b/src/components/MainContent.vue
index 4542d6d..f015131 100644
--- a/src/components/MainContent.vue
+++ b/src/components/MainContent.vue
@@ -1,6 +1,6 @@
 <template>
   <main role="main" class="col-md-10 ml-sm-auto col-lg-10 px-4">
-    <router-view :configData="mainConfig" @update="updateConfig($event)"></router-view>
+    <router-view :configData.sync="mainConfig"></router-view>
   </main>
 </template>
 
@@ -62,15 +62,21 @@ export default {
 		}
 	},
 	methods: {
-		updateConfig(eventData) {
-			this.mainConfig = eventData;
-			if (localStorage.getItem('remember') === 'true') {
-				localStorage.setItem('configData', JSON.stringify(this.mainConfig));
-			}
+	},
+	watch: {
+		mainConfig: {
+			handler() {
+				if (localStorage.getItem('remember') === 'true') {
+					localStorage.setItem('configData', JSON.stringify(this.mainConfig));
+				}
+			},
+			deep: true,
 		}
 	},
 	created() {
-		this.mainConfig = JSON.parse(localStorage.getItem("configData"));
+		if (localStorage.getItem("configData")) {
+			this.mainConfig = JSON.parse(localStorage.getItem("configData"));
+		}
 	},
 }
 </script>