3

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.