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

}

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

The console.log has been left in, should we need to diagnose a problem beyond a wrong


file path. Although the API can throw several different errors, we are going to assume for
this app that the error is due to a wrong path. If you wanted to cater for other errors in the


app, you can identify the error type by its status_code attribute. More details on this can


be found in the Dropbox API documentation.


Update your view to handle this new isLoading variable property. When set to error, the


isLoading variable is still "true," so within your loading element, add a new v-if to check


whether the loading variable is set to error:


<transition name="fade">
<div v-if="isLoading">
<div v-if="isLoading === 'error'">
<p>There seems to be an issue with the URL entered.
</p>
<p><a href="">Go home</a></p>
</div>
<div v-else>
Loading...
</div>
</div>
</transition>
Free download pdf