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

(singke) #1
Navigating through the File Tree and Loading Folders from the URL Chapter 5

files: []
}
for (let entry of response.entries) {
// Check ".tag" prop for type
if(entry['.tag'] == 'folder') {
structure.folders.push(entry);
} else {
}
}
this.structure = structure;
this.isLoading = false;
})
.catch(error => {
this.isLoading = 'error';
console.log(error);
});
},
updateStructure(path) {
this.isLoading = true;
this.getFolderStructure(path);
}
},
created() {
this.getFolderStructure(this.path);
},
watch: {
path() {
this.updateStructure(this.path);
}
},
});

Update the view to accept the prop as path:


<dropbox-viewer :path="path"></dropbox-viewer>

We now need to ensure the parent Vue instance has the correct path on both page load and


hash change. To avoid repetition, we are going to extend our Vue instance with both a


method and a created function.


Keep the path variable set to an empty string. Create a new method titled
updateHash() that removes the first character from the window hash and then sets the


path variable either to the hash or an empty string. Next, create a created() function that


runs the updateHash method.

Free download pdf