Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1

Caching the Current Folder Structure Using Vuex Chapter 6


createStructureAndSave(response) {
this.createFolderStructure(response)
this.$store.commit('structure', {
path: this.slug,
data: response
});
},

getFolderStructure() {
let data = this.$store.state.structure[this.slug];
if(data) {
this.createFolderStructure(data);
} else {
this.dropbox().filesListFolder({
path: this.path,
include_media_info: true
})
.then(this.createStructureAndSave)
.catch(error => {
this.isLoading = 'error';
console.log(error);
});
}

},
updateStructure() {
this.isLoading = true;
this.getFolderStructure();
}
},
created() {
this.getFolderStructure();
},
watch: {
path() {
this.updateStructure();
}
},
});

const store = new Vuex.Store({
state: {
path: '',
structure: {}
},
mutations: {
updateHash(state) {
let hash = window.location.hash.substring(1);
Free download pdf