Giter VIP home page Giter VIP logo

vue-drf's Introduction

vue-drf

A Vue.js connector to Django REST Framework (DRF) using vue-resource

Work in progress / Disclaimer

This package is not yet production ready and my first npm package, so it will probably not work for others out of the box.

Usage

install with npm: npm i -S asmaps/vue-drf

Install in Vue (e.g. in main.js):

import VueDrf from 'vue-drf'

Vue.use(VueDrf)

Dependencies

The plugin is written in ES6, so you will need babel to compile. It also uses the .vue component notation which is used as default in the vue-webpack template.

Components

drf-editable-model

Displays a model with editable fields from DRF. Uses an OPTIONS-request to dertermine fields and their properties (read_only, type, etc). Use a HyperlinkedModelSerializer on the django side, because vue-drf relies on the url field.

Non-readonly fields are clickable and change to an appropriate input field (uses vue-formular) to be edited.

The url field will automatically be displayed as a link.

Example code

JS:

export default {
  data () {
    data: {}
  },
  ready () {
    // or use the Resources stuff
    this.$http.get('https://your.drf-api.example.org/model/1/').then((response) => {
      this.data = response.data
    })
  }
}

Template:

<drf-editable-model v-if="data" :data="data"></drf-editable-model>

Accepts an optional fields property which should be a list of field names to display. If not given displays all fields in order from API. Use to only display a subset or specify the order of your fields.

<drf-editable-model :data="data" :fields="['id', 'created', 'name', 'url']"></drf-editable-model>

Events

drf-editable-model dispatches an event drf.model-changed when the model data changed and has been saved to the API. Contains the new object as payload.

vue-drf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

blodone

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.