1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# Resource
The resource service can be used globally `Vue.resource` or in a Vue instance `this.$resource`.
## Methods
* `resource(url, [params], [actions], [options])`
## Default Actions
```js
get: {method: 'GET'},
save: {method: 'POST'},
query: {method: 'GET'},
update: {method: 'PUT'},
remove: {method: 'DELETE'},
delete: {method: 'DELETE'}
```
## Example
```js
{
var resource = this.$resource('someItem{/id}');
// GET someItem/1
resource.get({id: 1}).then(response => {
this.item = response.body;
});
// POST someItem/1
resource.save({id: 1}, {item: this.item}).then(response => {
// success callback
}, response => {
// error callback
});
// DELETE someItem/1
resource.delete({id: 1}).then(response => {
// success callback
}, response => {
// error callback
});
}
```
## Custom Actions
```js
{
var customActions = {
foo: {method: 'GET', url: 'someItem/foo{/id}'},
bar: {method: 'POST', url: 'someItem/bar{/id}'}
}
var resource = this.$resource('someItem{/id}', {}, customActions);
// GET someItem/foo/1
resource.foo({id: 1}).then(response => {
this.item = response.body;
});
// POST someItem/bar/1
resource.bar({id: 1}, {item: this.item}).then(response => {
// success callback
}, response => {
// error callback
});
}
```
|