air-vue-model
AIR-VUE-MODEL
Table of Contents
Instalation
$ npm install marked
Model
Add folder models in src. Add a file to the directory that will contain the model, for example user.
Simple usage
src/models/user.js
const m = require('air-vue-model/model')()
m.name = "user"
m.url = "users"
module.exports = m
Create a models.js file in src and register the model in Vue.prototype for global use.
src/models.js
import Vue from 'vue'
Vue.prototype.$user = Vue.observable(require('./models/user'))
Methods
loadList(params)
Sends a GET request to get the list and set it to list. You can pass query params to query by passing them as an object in the method call.
const params = {
page_size: 15
}
this.$user.loadList(params).then(result => {
console.log(result)
}).catch(e => {
console.log(e)
})
loadItem(id)
Sends a GET request to get an item, the value is set in the item field. If id is "new" then item will be
set to the value from default.
const id = 1
this.$user.loadItem(id).then(result => {
console.log(result)
}).catch(e => {
console.log(e)
})
create(data = null)
Sends a POST request to create an item. If data is not passed, then the value will be taken from item. The new value will be set to item.
const data = {
name: "demo"
}
this.$user.create(data).then(result => {
console.log(result)
}).catch(e => {
console.log(e)
})
update(data = null)
Sends a POST request to update an item. If data is not passed, then the value will be taken from item. The updated value will be set to item.
const data = {
id: 3,
name: "updated demo"
}
this.$user.update(data).then(result => {
console.log(result)
}).catch(e => {
console.log(e)
})
destroy(id = null)
Sends a DELETE method to delete an object. If id is not passed, it will be taken from item.
this.$user.destroy(3)
getRoutes()
Get routes from item.routes.
Required fields:
- component
- name
To go to the specified route, you must specify the name from the model + the name of the route.
// create model
const m = require('air-vue-model/model')()
m.name = "user"
m.url = "users"
m.routes = [
{name: 'list', component: require('./components/ListUser.vue')},
{name: 'item', component: require('./components/ItemUser.vue'), single: true}
]
module.exports = m
// push to list
this.$router.push({
name: 'userList'
})
// push to item
this.$router.push({
name: 'userItem',
params: {
userId: 3
}
})
Optional fields:
- single
If single is true, then when trying to open this path, the value will be loaded automatically using the ** loadItem** method.
- path
The default is equal to url, if single is true, then the following construction will be used:
`${self.url}/:${self.name}Id`
- auth
Check for user presence. If the user is absent, an authorization attempt will be made. On error, an error will be thrown in router.
- another fields will be set in meta
Related Packages
Version History
| Version | Released | License |
|---|---|---|
| 1.0.81 | MIT | |
| 1.0.80 | MIT | |
| 1.0.79 | MIT | |
| 1.0.78 | MIT | |
| 1.0.77 | MIT | |
| 1.0.76 | MIT | |
| 1.0.75 | MIT | |
| 1.0.74 | MIT | |
| 1.0.73 | MIT | |
| 1.0.72 | MIT | |
| 1.0.71 | MIT | |
| 1.0.70 | MIT | |
| 1.0.69 | MIT | |
| 1.0.68 | MIT | |
| 1.0.67 | MIT | |
| 1.0.66 | MIT | |
| 1.0.65 | MIT | |
| 1.0.64 | MIT | |
| 1.0.63 | MIT | |
| 1.0.62 | MIT | |
| 1.0.61 | MIT | |
| 1.0.60 | MIT | |
| 1.0.59 | MIT | |
| 1.0.58 | MIT | |
| 1.0.56 | MIT | |
| 1.0.55 | MIT | |
| 1.0.54 | MIT | |
| 1.0.53 | MIT | |
| 1.0.52 | MIT | |
| 1.0.51 | MIT |
Showing the latest 30 of 80. See every release on npm