@yurderi/vue models

A better way to use entities in vue.js

Version: 1.1.0 Updated: 06/17/2019

By: yurderi License: MIT

Downloads Last 30 Days: 76

Install

npm i @yurderi/vue-models
yarn add @yurderi/vue-models

Repository: https://github.com/yurderi/vue-models

CDNs

bundle.run: https://bundle.run/@yurderi/vue-models

jsDelivr: https://cdn.jsdelivr.net/npm/@yurderi/vue-models

unpkg: https://unpkg.com/@yurderi/vue-models

vue-models

A better way to use entities in vue.js

Requirements

  • axios
  • vue

Installation

yarn add @yurderi/vue-models

Basic usage

import Vue from 'vue'
import VueModels from '@yurderi/vue-models'
import axios from 'axios'

Vue.use(VueModels, {
    models: require.context(__dirname + '/models/'),
    http: axios.create()
})

// ... later

Vue.models.user.list().then(users => {
    console.log(users)
})

// ... or

Vue.component('v-test', {
    data: () => ({
        items: []
    }),
    mounted() {
        this.$models.user.list().then(users => this.items = users)
    }
})

API Documentation

Method Description
public create () : Object Creates an empty model containing default values
public save (data: Array) : Promise<Object> Creates/saves a model entity
public get (id: Integer) : Promise<Object> Gets a model by id
public remove (model: Object) : Promise<Boolean> Removes a model by object (identified by id)
public list (params: Object) : Promise<Array> List all models with additional params
public filter (models: Object, search: String) : Array Filter a set of models by search phrase
private __normalizeRow (data: Object) : Object Applies types to model fields

Contributors



tyurderi
commits

DevDependencies


Categories: Vue js
Tags: