sync instead of emit for configdata

This commit is contained in:
Bart van der Braak 2020-02-04 23:21:35 +01:00
parent 07bc880c60
commit 0ccecbef31
2 changed files with 14 additions and 12 deletions

View file

@ -176,15 +176,11 @@ export default {
}); });
} }
}, },
beforeRouteLeave (to, from, next) {
this.$emit('update',this.configData);
next()
},
created() { created() {
this.setRemember() this.setRemember()
}, },
watch: { watch: {
configFile: function () { configFile() {
if (window.File && window.FileReader && window.FileList && window.Blob) { if (window.File && window.FileReader && window.FileList && window.Blob) {
this.readFile(this.configFile); this.readFile(this.configFile);
} else { } else {

View file

@ -1,6 +1,6 @@
<template> <template>
<main role="main" class="col-md-10 ml-sm-auto col-lg-10 px-4"> <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> </main>
</template> </template>
@ -62,15 +62,21 @@ export default {
} }
}, },
methods: { methods: {
updateConfig(eventData) { },
this.mainConfig = eventData; watch: {
if (localStorage.getItem('remember') === 'true') { mainConfig: {
localStorage.setItem('configData', JSON.stringify(this.mainConfig)); handler() {
} if (localStorage.getItem('remember') === 'true') {
localStorage.setItem('configData', JSON.stringify(this.mainConfig));
}
},
deep: true,
} }
}, },
created() { created() {
this.mainConfig = JSON.parse(localStorage.getItem("configData")); if (localStorage.getItem("configData")) {
this.mainConfig = JSON.parse(localStorage.getItem("configData"));
}
}, },
} }
</script> </script>