To start, we need to create a new Vuex module. This example module will be called authentication, and will store the credentials data for the user.
In these steps, we will create the authentication module for Vuex:
- Create a new folder called authentication in the src/store folder.
- In this newly created folder, create a new file called state.js, and open it.
- Create a function called generateState that will return a JavaScript object with the properties of data.username, data.token, data.expiresAt, loading, and error:
const generateState = () => ({
data: {
username: '',
token: '',
expiresAt: null,
},
loading: false,
error: null,
});
- Create an export default object at the end of the file. This object will be a JavaScript object. We will destruct the return of the generateState function:
export default { ...generateState() };
- Create a new file called index.js in the authentication folder inside the src/store folder...