Skip to content

Instantly share code, notes, and snippets.

@morrelinko
Created October 15, 2016 17:04
Show Gist options
  • Save morrelinko/d70fb31f14b57de0c7123fa29c239e99 to your computer and use it in GitHub Desktop.
Save morrelinko/d70fb31f14b57de0c7123fa29c239e99 to your computer and use it in GitHub Desktop.
Vue Noty Plugin
'use strict'
import Vue from 'vue'
import Notify from './plugins-notify'
Vue.use(Notify)
const app = new Vue({
el: '#app',
mounted () {
this.$notify.success('Yayy!! It works')
}
})
'use strict'
import noty from 'noty'
import $ from 'jquery'
let Notify = function () {
}
Notify.prototype.show = function (type, message, options = {}) {
let payload = {
type,
text: message,
timeout: 2000,
layout: 'bottomRight'
}
return noty($.extend(payload, options))
}
let helpers = ['alert', 'error', 'success', 'info', 'warning']
helpers.forEach(helper => {
Notify.prototype[helper] = function (message, options = {}) {
return this.show(helper, message, options)
}
})
Notify.install = function (Vue, options) {
Vue.notify = new Notify()
Object.defineProperties(Vue.prototype, {
$notify: {
get () {
return Vue.notify
}
}
})
}
export default Notify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment