pages.js 834 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import api from '@/api'
  2. import { Page } from '@/api/queries'
  3. export default {
  4. state: {
  5. welcome: undefined,
  6. intro: undefined,
  7. ids: {
  8. welcome: 208,
  9. intro: 207
  10. },
  11. visited: localStorage.getItem('visited') === 'true'
  12. },
  13. mutations: {
  14. 'SET_PAGE' (state, { slug, page }) {
  15. state[slug] = page
  16. },
  17. 'SET_VISITED' (state, visited) {
  18. state.visited = visited
  19. localStorage.setItem('visited', visited)
  20. }
  21. },
  22. actions: {
  23. async 'QUERY_PAGE' ({ state, commit, dispatch, getters }, slug) {
  24. if (state[slug] !== undefined) return state[slug]
  25. return api.query(Page, { id: state.ids[slug] }).then(data => {
  26. commit('SET_PAGE', { slug, page: data.page })
  27. return state[slug]
  28. })
  29. }
  30. },
  31. getters: {
  32. visited: state => state.visited
  33. }
  34. }