1.0.81 • Published 3 years ago

air-vue-model v1.0.81

Weekly downloads
53
License
MIT
Repository
-
Last release
3 years ago

AIR-VUE-MODEL

Table of Contents

  1. Instalation
  2. Model
    1. Simple usage
    2. Methods
      1. loadList
      2. loadItem
      3. create
      4. destroy
      5. getRoutes
    3. Required fields
    4. Optional fields

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
1.0.81

3 years ago

1.0.80

3 years ago

1.0.79

3 years ago

1.0.77

3 years ago

1.0.76

3 years ago

1.0.75

3 years ago

1.0.78

3 years ago

1.0.74

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.70

3 years ago

1.0.66

3 years ago

1.0.69

3 years ago

1.0.68

3 years ago

1.0.67

3 years ago

1.0.62

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.55

3 years ago

1.0.56

3 years ago

1.0.54

3 years ago

1.0.53

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.52

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.40

3 years ago

1.0.39

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.34

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.26

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.23

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.11

3 years ago

1.0.13

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago