Giter VIP home page Giter VIP logo

vue-sails.io's Introduction

Install

npm install vue-sails.io --save

Requirements

At the moment Vuex is required to work

Use

Use the plugin

In the main file where you bootstrap most of your plugin add 'VueSailsIO'

import VueSailsIO from 'vue-sails.io'
Vue.use(VueSailsIO, 'http://localhost:1337')

In a Vue-component

Add the object 'sails', create one or more named objects,

<template lang="pug">
section.container
  .columns
    .column.is-narrow
      form(@submit.prevent="user({ username: username })")
        p.control.has-addons
          input.input(type="text" v-model="username" placeholder="Text")
          button.button(type="submit") Send
    .column
      .box
        article.media(v-for="user of users") {{ user.username }}
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters([ 'users' ])
  },
  sails: {
    user: {
      method: 'get',      // required, options are: get, post, put, delete
      url:  '/user',      // optional, defaults to '/' + [the object name] (this case '/user')
      mutation: 'users',  // optional, defaults to [the object name], can be false to not create a listener
      remove: false       // optional, defaults to true, remove the listener when component is destroyed
    }
  },
  data () {
    return {
      username: ''
    }
  }
}
</script>

Manually

The sails object is mapped to 'this.$sails'

The following functions are exposed:

  1. this.$sails.addListener(socket, mutation)
  2. this.$sails.removeListener(socket)
  3. this.$sails.hasListener(socket)
  4. this.$sails.socket.get(url, data) // or post, delete, put
  5. this.$sails.socket.on(url, function(data) {})

Changelog

1.0.2

No need to manually create mutation

vue-sails.io's People

Contributors

kristofvandam avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.