All Projects → cklmercer → Vue Events

cklmercer / Vue Events

Licence: mit
Simple event handling for Vue.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Events

Findviewbyme
A plugin for android developer, with the plugin you can generate "findViewById" code quickly.
Stars: ✭ 215 (-8.12%)
Mutual labels:  plugin
Protoc Gen Lint
A plug-in for Google's Protocol Buffers (protobufs) compiler to lint .proto files for style violations.
Stars: ✭ 221 (-5.56%)
Mutual labels:  plugin
Ctrlp Py Matcher
Fast vim CtrlP matcher based on python
Stars: ✭ 229 (-2.14%)
Mutual labels:  plugin
Fastlogin
Checks if a minecraft player has a valid paid account. If so, they can skip offline authentication automatically. (premium auto login)
Stars: ✭ 216 (-7.69%)
Mutual labels:  plugin
Better Mybatis Generator
在idea的数据库工具中,直接对表生成mybatis相关的代码文件。
Stars: ✭ 219 (-6.41%)
Mutual labels:  plugin
Mulog
μ/log is a micro-logging library that logs events and data, not words!
Stars: ✭ 222 (-5.13%)
Mutual labels:  events
Php Mysql Replication
Pure PHP Implementation of MySQL replication protocol. This allow you to receive event like insert, update, delete with their data and raw SQL queries.
Stars: ✭ 213 (-8.97%)
Mutual labels:  events
Miaow
A set of plugins for Sketch include drawing links & marks, UI Kit & Color sync, font & text replacing.
Stars: ✭ 2,536 (+983.76%)
Mutual labels:  plugin
Tinyfaces Sketch Plugin
Fill selected layers in Sketch with free stock avatars
Stars: ✭ 221 (-5.56%)
Mutual labels:  plugin
Craftbook
🔧 Machines, ICs, PLCs, and more!
Stars: ✭ 226 (-3.42%)
Mutual labels:  plugin
Cartographer
A GPU powered Terrain editor and renderer for Godot Engine
Stars: ✭ 216 (-7.69%)
Mutual labels:  plugin
Cordova Plugin Nativeaudio
The low latency audio plugin is designed to enable low latency and polyphonic audio from Cordova/PhoneGap applications, using a very simple and basic API.
Stars: ✭ 220 (-5.98%)
Mutual labels:  plugin
Vim Yoink
Vim plugin that maintains a yank history to cycle between when pasting
Stars: ✭ 225 (-3.85%)
Mutual labels:  plugin
Resharper Fsharp
F# support in JetBrains Rider
Stars: ✭ 216 (-7.69%)
Mutual labels:  plugin
Photofilters
photofilters library for flutter
Stars: ✭ 229 (-2.14%)
Mutual labels:  plugin
Blenderseed
appleseed plugin for Blender
Stars: ✭ 214 (-8.55%)
Mutual labels:  plugin
Caddy Authz
Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
Stars: ✭ 221 (-5.56%)
Mutual labels:  plugin
Wordpress Plugin Boilerplate Tutorial
Tutorials and Examples for WordPress Plugin Boilerplate, a foundation for WordPress Plugin Development.
Stars: ✭ 232 (-0.85%)
Mutual labels:  plugin
Awesome Xcode Extensions
Awesome native Xcode extensions.
Stars: ✭ 2,628 (+1023.08%)
Mutual labels:  plugin
React Native Add Calendar Event
Create, view or edit events in react native using the standard iOS / Android dialogs
Stars: ✭ 225 (-3.85%)
Mutual labels:  events

vue-events

A Vue.js plugin that simplify events.

Works with both Vue 1.0 & Vue 2.0.

Installation

1.) Install package via Yarn or NPM
$ yarn add vue-events

$ npm install vue-events
2.) Install plugin within project.
import Vue from 'vue'
import VueEvents from 'vue-events'
Vue.use(VueEvents)

window.Vue = require('vue')
require('vue-events')

Methods

Method Params Description Docs
vm.$events.$emit event, payload Emit the event with the given payload. vm.$emit
vm.$events.emit event, payload Emit the event with the given payload. Alias for vm.$events.$emit vm.$emit
vm.$events.fire event, payload Emit the event with the given payload. Alias for vm.$events.$emit vm.$emit
vm.$events.$on event, callback Listen for the event with the given callback. vm.$on
vm.$events.on event, callback Listen for the event with the given callback. Alias for vm.$events.$on vm.$on
vm.$events.listen event, callback Listen for the event with the given callback. Alias for vm.$events.$on vm.$on
vm.$events.$off event, callback Remove event listener(s) for the event vm.$off
vm.$events.off event, callback Remove event listener(s) for the event. Alias for vm.$events.$off vm.$off
vm.$events.remove event, callback Remove event listener(s) for the event Alias for vm.$events.$off vm.$off

Usage

The $events prototype object.

This plugin extends Vue.prototype to include a new $events object, which is a just a plain vm that will serve as your global event bus. The $events vm has a couple aliases for the standard event methods.

Firing an event

There are 3 methods that fire events.

Note: $events.fire & $events.emit are aliases for $events.$emit

new Vue({

  data() {
    return {
      eventData: {
        foo: 'baz'
      }
    }
  },

  mounted() {
    this.$events.fire('testEvent', this.eventData);
    this.$events.emit('testEvent', this.eventData);
    this.$events.$emit('testEvent', this.eventData);
  }

})

Listening for an event

There are 3 methods that register event listeners.

Note: $events.listen & $events.on are aliases for $events.$on.

new Vue({
  mounted() {
    this.$events.listen('testEvent', eventData => console.log(eventData));
    this.$events.on('testEvent', eventData => console.log(eventData));
    this.$events.$on('testEvent', eventData => console.log(eventData));
  }
})

Removing an event listener

There are 3 methods that remove event listeners.

Note: $events.off & $events.remove are aliases for $events.$off.

new Vue({
  mounted() {
    this.$events.on('testEvent', eventData => console.log(eventData));
  },

  beforeDestroy() {
    this.$events.$off('testEvent')
    this.$events.off('testEvent')
    this.$events.remove('testEvent')
  }
})

The events component options.

Provide an events map as part of your component options and vue-events will automatically call $on when the component is mounted and $off when the component is destroyed.

new Vue({
  events: {
    testEvent(eventData){
       console.log(eventData)    
    }
  }  
})

Inside the event handlers, this is bound to the component instance. This way you can access your component's data, props, computed, methods, etc. For example:

new Vue({
  events: {
    onShowAlert(message){
       this.modalVisible = true
       this.message = message
    }
  }  
})

Demo

If you'd like to demo vue-events try vue-mix

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].