Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I defined a vue-resource:

resources.js:

import Vue from 'vue'
import VueResource from 'vue-resource'

Vue.use(VueResource);

export const Team = Vue.resource('team{/id}{/action}');

So, then if I call the get method on that resource:

api = require('.api/resources')
api.Team.get({
    id: 3233,
    action: 'details',
}).then(function(response) {
    // ....
});

This ajax call makes a request to:

/team/3233/details

Problem:

But when I use .update or .save rather than .get, the request url is not as expect:

api = require('.api/resources')
api.Team.update({
    id: 3233,
    action: 'details',
}).then(function(response) {
    // ....
});

I only send a request to /team with all parameters transferred in the request body.

How can I specifies the url parameters in such a .save or .update ajax call?

share|improve this question
up vote 0 down vote accepted

Well simply adding a second parameter on the method call is ok:

api = require('.api/resources')
api.Team.update({
    id: 3233,
    action: 'details',
}, {}).then(function(response) {
    // ....
});

When the vue-resource calling ajax on a method with body, it accepts either one or two data parameter.

If one single parameter is given, it was treated as the body payload.

If two parameters are given, the first is the routing parameter, while the second one is the body payload.

So, if want to specify the routing parameter, just give an empty object as the second parameter.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.