Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Id Parameter is always undefined #55

Closed
Vad1mo opened this issue Mar 6, 2018 · 4 comments
Closed

Id Parameter is always undefined #55

Vad1mo opened this issue Mar 6, 2018 · 4 comments

Comments

@Vad1mo
Copy link

Vad1mo commented Mar 6, 2018

I have this action definition

  .get({
    action: 'getUser',
    property: 'user',
    path: ({ id }) => {
      console.log('The Arg is ', id)
      return `/tenants/${id}`
    }
  })

And I am dispatching like this:

Try 1:

js
created: function () {
        this.$store.dispatch({
        type: 'getUser',
        data: { id: this.$route.params.id }
      })

Try 2:

js
created: function () {
      this.$store.dispatch('getUser', {
        data: {
          id: 1
        }
      })

Try 3:

js
created: function () {
      this.$store.dispatch('getUser', { id: 1243 }, null )

In all cases the id is undefined. IMHO it should have an id.

@christianmalek
Copy link
Owner

christianmalek commented Mar 6, 2018

Hi Vadim,

There is another property params. Please see https://github.com/christianmalek/vuex-rest-api#calling-the-actions I've decided to separate data and params because it's not always wanted to have the params in your body data.

This should work:

this.$store.dispatch('getUser', {
    // params is available in the path function
    params: {
        id: 1
    },
    // optional data
    data: {
        //...
    }
})

@christianmalek
Copy link
Owner

@Vad1mo I've updated my answer.

@Vad1mo
Copy link
Author

Vad1mo commented Mar 6, 2018

thank you for the quick response, this works perfectly. The example would be a perfect candidate for the readme :)
What confused me was this syntax getPost({params: {someParam: 5, anotherParam: "foo"}}) it wasn't introduced (at least in the quick start) before as action and arguments.

@Vad1mo Vad1mo closed this as completed Mar 6, 2018
@christianmalek
Copy link
Owner

The Readme has definitely room for improvement. It's too long and lacks on examples. Feel free to PR. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants