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

(singke) #1
Getting a List of Files Using the Dropbox API Chapter 4

This code uses JavaScript promises, which are a way of adding actions to code without


requiring callback functions. If you are unfamiliar with promises, check out this blog post
from Google (https:/​/​developers.​google.​com/​web/​fundamentals/​primers/​promises).


Take a note of the first line, particularly the path variable. This lets us pass in a folder path


to list the files and folders within that directory. For example, if you had a folder called
images in your Dropbox, you could change the parameter value to /images and the file


list returned would be the files and folders within that directory.


Open your JavaScript console and check the output; you should get an array containing


several objects - one for each file or folder in the root of your Dropbox.


Displaying your data and using Vue to get it


Now that we can retrieve our data using the Dropbox API, it's time to retrieve it within our


Vue instance and display in our view. This app is going to be entirely built using
components so we can take advantage of the compartmentalized data and methods. It will


also mean the code is modular and shareable, should you want to integrate into other apps.


We are also going to take advantage of the native Vue created() function - we'll cover it


when it gets triggered in a bit.


Create the component


First off, create your custom HTML element, , in your View. Create a