This uses a Nuxt/VueJS Framework. To store data VueX is being used for local storage.
For a detailed explanation on how things work, check out Nuxt.js docs.
- Markdown: https://www.npmjs.com/package/@nuxtjs/markdownit for markdown support.
- Axios: https://axios.nuxtjs.org/ for API support
- API Testing: https://github.com/typicode/json-server but put in a separate project area.
Used instructions at https://gist.github.com/benmccallum/33ff008660218a578fc27fd33f51d1c1
Why Your Third-Party Plugin Don’t Work in Nuxt and How to Fix it
VueX will not remember the data store if you use the browser arrow keys. This is especially true if you leave the single page app. To demonstrate this:
- Open an input page
- Fill in some fields
- Navigate using the Previous or Next page buttons
- Navigate back to to the page you fill in the fields using the Previous or Next page buttons
- You will see the values in the fields.
- Close the window
- Open the same input page as in step 1
- There is no data in the fields.
The way to get around this is to use local storage or cookies with the following GitHub - robinvdvleuten/vuex-persistedstate: Persist and rehydrate your Vuex state between page reloads.
npm install vuex-persistedstate
npm install js-cookie
In Store/index.js
import createPersistedState from 'vuex-persistedstate';
import Cookies from "js-cookie";
Vue.use(Vuex)
const store = () => new Vuex.Store({
plugins: [ createPersistedState({
namespace: 'cmr-app',
initialState: {},
expires: 7 * 24 * 60 * 60 * 1000,
storage: {
getItem: key => Cookies.get(key),
setItem: (key, value) => Cookies.set(key, value),
removeItem: key => Cookies.remove(key)
}
}) ],
state: {
todos: [],
From https://scotch.io/tutorials/implementing-authentication-in-nuxtjs-app
Note: js-cookie might of already of been installed.
npm install @nuxtjs/auth
npm install js-cookie --save
npm install cookieparser --save
Add the following to nuxt.config.js
modules: [
'@nuxtjs/axios',
'@nuxtjs/auth'
],
axios: {
baseURL: 'http://127.0.0.1:3333/api'
},
auth: {
strategies: {
local: {
endpoints: {
login: { url: 'login', method: 'post', propertyName: 'data.token' },
user: { url: 'me', method: 'get', propertyName: 'data' },
logout: false
}
}
}
}