Created
July 30, 2020 07:34
-
-
Save butschster/e348455e349ac0da4af8f39fa1fd10e7 to your computer and use it in GitHub Desktop.
Vue notifications
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
import Noty from 'noty' | |
import Vue from 'vue' | |
const notify = { | |
/** | |
* @param {String} text | |
* @returns {*} | |
*/ | |
success(text) { | |
return this.message(text, "success") | |
}, | |
/** | |
* @param {String} text | |
* @returns {*} | |
*/ | |
info(text) { | |
return this.message(text, "info") | |
}, | |
/** | |
* @param {String} text текст | |
* @returns {*} | |
*/ | |
error(text) { | |
return this.message(text, "error") | |
}, | |
/** | |
* @param {String} text | |
* @returns {*} | |
*/ | |
warning(text) { | |
return this.message(text, 'warning') | |
}, | |
/** | |
* @param {String} text | |
* @returns {*} | |
*/ | |
alert(text) { | |
return this.message(text, 'alert') | |
}, | |
/** | |
* @param {String} text | |
* @param {String} type | |
* @returns {*} | |
*/ | |
message(text, type) { | |
return new Noty({ | |
type, | |
text, | |
theme: 'mint', | |
timeout: 1000 | |
}).show(); | |
}, | |
/** | |
* @param {String} message текст | |
* @return Promise | |
*/ | |
confirm(message) { | |
return new Promise((resolve, reject) => { | |
new Noty({ | |
text: message, | |
buttons: [ | |
Noty.button('YES', 'btn btn-success', function () { | |
resolve() | |
}, {id: 'button1', 'data-status': 'ok'}), | |
Noty.button('NO', 'btn btn-error', function () { | |
reject() | |
n.close() | |
}) | |
] | |
}).show() | |
}) | |
} | |
} | |
Vue.prototype.$notify = notify | |
export default notify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment