christianmalek / vuex-rest-api

A utility to simplify the use of REST APIs with Vuex
http://vuex-rest-api.org
MIT License
382 stars 48 forks source link

Problem recreating example from docs #68

Closed arjanski closed 6 years ago

arjanski commented 6 years ago

Hello,

First of all thank you for this great helper tool. I'm having troubles using it (see below), but looks just like what my project needs. I hope a noob question is okay:

When I try recreating the example code from the docs, vue devtools show me a state with empty objects (e.g. posts: Array[0], ``pending: ... post: false ... ).

I've set up a new Vue project using vue-cli 3, installed vuex-rest-api 2.8 and axios 0.18.

My store.js

import Vuex from "vuex"
import Vue from "vue"
// Step 1
import Vapi from "vuex-rest-api"

Vue.use(Vuex)

// Step 2
const posts = new Vapi({
  baseURL: "https://jsonplaceholder.typicode.com",
    state: {
      posts: []
    }
  })
  // Step 3
  .get({
    action: "getPost",
    property: "post",
    path: ({ id }) => `/posts/${id}`
  })
  .get({
    action: "listPosts",
    property: "posts",
    path: "/posts"
  })
  .post({
    action: "updatePost",
    property: "post",
    path: ({ id }) => `/posts/${id}`
  })
  // Step 4
  .getStore()

// Step 5
export const store = new Vuex.Store(posts)

the Githubissues.

  • Githubissues is a development platform for aggregating issues.