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

(singke) #1
Pre-Caching Other Folders and Files for Faster Navigation Chapter 7

* Loop through the breadcrumb and cache parent folders
*/
cacheParentFolders() {
let parents = this.$store.state.breadcrumb;
parents.reverse().shift();

for(let parent of parents) {
this.getFolderStructure(parent.path);
}
}
},

created() {
// Display the current path & cache parent folders
this.displayFolderStructure();
this.cacheParentFolders();
},

watch: {
// Update the view when the path gets updated
path() {
this.displayFolderStructure();
}
}
});

Let us also check the Vuex store:


/**
* The Vuex Store
*/
const store = new Vuex.Store({
state: {
// Current folder path
path: '',

// The current breadcrumb
breadcrumb: [],

// The cached folder contents
structure: {},
},
mutations: {
/**
* Update the path & breadcrumb components
* @param {object} state The state object of the store
*/
updateHash(state) {
Free download pdf