Book Image

Vue.js 2.x by Example

By : Mike Street
Book Image

Vue.js 2.x by Example

By: Mike Street

Overview of this book

Vue.js is a frontend web framework which makes it easy to do just about anything, from displaying data up to creating full-blown web apps, and has become a leading tool for web developers. This book puts Vue.js into a real-world context, guiding you through example projects that helps you build Vue.js applications from scratch. With this book, you will learn how to use Vue.js by creating three Single Page web applications. Throughout this book, we will cover the usage of Vue, for building web interfaces, Vuex, an official Vue plugin which makes caching and storing data easier, and Vue-router, a plugin for creating routes and URLs for your application. Starting with a JSON dataset, the first part of the book covers Vue objects and how to utilize each one. This will be covered by exploring different ways of displaying data from a JSON dataset. We will then move on to manipulating the data with filters and search and creating dynamic values. Next, you will see how easy it is to integrate remote data into an application by learning how to use the Dropbox API to display your Dropbox contents in an application In the final section, you will see how to build a product catalog and dynamic shopping cart using the Vue-router, giving you the building blocks of an e-commerce store.
Table of Contents (13 chapters)

Using the Vuex store for the folder path

The first step in using the Vue store for our global Dropbox path variable is to move the data object from the Vue instance to the Store, and rename it to state:

const store = new Vuex.Store({
state: {
path: ''
}
});

We also need to create a mutation to allow the path to be updated from the hash of the URL. Add a mutations object to the store and move the updateHash function from the Vue instance—don't forget to update the function to accept the store as the first parameter. Also, change the method so it updates state.path rather than this.path:

const store = new Vuex.Store({
state: {
path: ''
},
mutations: {
updateHash(state) {
let hash = window.location.hash.substring(1);
state.path = (hash || '');
}
}
});

By moving the path variable and mutation to the store, it makes...