Created
October 15, 2016 17:04
-
-
Save morrelinko/d70fb31f14b57de0c7123fa29c239e99 to your computer and use it in GitHub Desktop.
Vue Noty Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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') | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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