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

this.getFolderStructure(this.path).then(data => {
});
}

This code passes the path object of the component into the method. This path is the current


path that the user is trying to view. Once the data is returned, we can assign it to the data


variable, which can then be used inside the function.


Loop through the result and add each item to either the folders or files array

We are already familiar with the code that loops through the entries and examines the .tag


attribute of each one. If this results in a folder, it is added to the structure.folders


array, otherwise it is appended to structure.files.


We are only storing the entries in the cache, so make sure the for loop is updated to use the


data as is, rather than accessing the property of entries:


displayFolderStructure() {
this.isLoading = true;

const structure = {
folders: [],
files: []
}
this.getFolderStructure(this.path).then(data => {
for (let entry of data) {
// Check ".tag" prop for type
if(entry['.tag'] == 'folder') {
structure.folders.push(entry);
} else {
structure.files.push(entry);
}
}
});
}
Free download pdf