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...