Skip to content

vueui/resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

resource

var Vue = require('vue')
var vueResource = require('vueui-resource')

var options = {
	host: '',
	namespace: '/api/v0',
	resources: {
		cats: {
			path: '/cats',
			parse: function(res) {
				return res['data']
			}
		},
		rooms: {
			path: '/rooms',
			resources: {
				equipment: {
					path: '/{roomId}/equipment'
				},
				keys: {
					path: '/{roomId}/keys'
				}
			}
		},
		names: {
			path: '/names/{team}'
		}
	}
}

Vue.use(vueResource, options)

var app = new Vue({
	resources: function($resource) {
		var roomQuery = $resource('rooms', 'room').query({ house: 'White House' }).limit(1).find()
		var	equipmentQuery = $resource('rooms.equipment', 'equipment').params({ roomId: 1 }).find()
		var keysQuery = $resource('rooms.keys', 'keys').params({ roomId: 1 }).find()
			
		return [ roomQuery, equipmentQuery, keysQuery ]
	}
})

Finding records

app.$resource('users', 'myUsers').find().then(function(users) {
	console.log(users)
})

Creating records

app.$resource('cats', 'myCat').create({ name: 'Kitten' }).then(function(cat) {
	console.log(cat) // => { id: 1, name: 'Kitten' }
})

Saving records

app.myCat.name = 'New Cat'
app.$resource('myCat').save().then(function(cat) {
	// cat.name = 'New Name'
})

Deleting records

app.$resource('myCat').delete(true).then(function() {
	// DELETE /cats/1
	// app.myCat === null
})

Reloading records

app.$resource('myUsers').reload().then(function(users) {
	// updated users
})

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published