Git Product home page Git Product logo

vue-resource's Introduction

vue-resource

Resource plugin for Vue.js (v0.11).

The plugin provides services for making web requests and handle responses using a XMLHttpRequest or JSONP.

HTTP

The http service can be used globally Vue.http or in a Vue instance this.$http.

List of methods:

  • Vue.http.get(url, [data], [success], [options])
  • Vue.http.post(url, [data], [success], [options])
  • Vue.http.put(url, [data], [success], [options])
  • Vue.http.patch(url, [data], [success], [options])
  • Vue.http.delete(url, [data], [success], [options])
  • Vue.http.jsonp(url, [data], [success], [options])

Usage

  new Vue({

      ready: function() {

        // GET request
        this.$http.get('/someUrl', function (data, status, request) {

            // set data on vm
            this.$set('someData', data)

        }).error(function (data, status, request) {
            // handle error
        })

      }

  })

Resource

The resource service can be used globally Vue.resource or in a Vue instance this.$resource.

List of methods:

  • Vue.resource(url, [params], [actions])

List of default actions:

get: {method: 'GET'},
save: {method: 'POST'},
query: {method: 'GET'},
remove: {method: 'DELETE'},
delete: {method: 'DELETE'}

Usage

  new Vue({

      ready: function() {

        var resource = this.$resource('someItem/:id');

        // get item
        resource.get({id: 1}, function (item, status, request) {
            this.$set('item', item)
        })

        // save item
        resource.save({id: 1}, {item: this.item}, function (data, status, request) {
            // handle success
        }).error(function (data, status, request) {
            // handle error
        })

        // delete item
        resource.delete({id: 1}, function (data, status, request) {
            // handle success
        }).error(function (data, status, request) {
            // handle error
        })

      }

  })

Asset

The asset service can be used globally Vue.asset or in a Vue instance this.$asset.

List of methods:

  • Vue.asset(assets, [success], [error])
  • Vue.asset.css(url, [success], [error])
  • Vue.asset.js(url, [success], [error])
  • Vue.asset.image(url, [success], [error])

Usage

  new Vue({

      ready: function() {

        this.$asset({
            css   : [
                'lib/style.css',
                'lib2/style.css'
            ],
            js    : [
                'lib/script.js',
                'lib2/script.js',
            ],
            image : [
                'media/image1.png',
                'media/image2.png',
            ]

        }, function() {

            this.obj = new Lib(this.$el);

        }).error(function(e) {
            // handle error
        });

      }

  })

vue-resource's People

Contributors

aheinze avatar jwondrusch avatar steffans avatar

Watchers

 avatar  avatar

Forkers

target-v

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.