vue-toasted is a cool material toast plugin with variety of options and styles. it is touch compatible and responsive. issues and pr's are always welcome
Checkout the Interactive Demo here.
It is simple. couple of lines all what you need.
# install it via npm
npm install vue-toasted --save
// register the plugin on vue
import Toasted from 'vue-toasted';
Vue.use(Toasted)
// you can also pass options, check options reference below
Vue.use(Toasted, Options)
// you can call like this in your component
this.$toasted.show('hello billo')
// and also
Vue.toasted.show('hola billo');
All Good Now you have this cool toast in your project.. let's take a look at the api
vue-toasted has methods which makes it much easier to use
all the below methods return the Toasted Object
of the toast.
Vue.toasted.success( {string | html } message, {object} options)
// available methods
Vue.toasted.show(message, options)
Vue.toasted.success(message, options)
Vue.toasted.info(message, options)
Vue.toasted.error(message, options)
check the examples to see how to manipulate the object.
// html element of the toast
el : HtmlElement
// change text or html of the toast
text : Function(text)
// fadeAway the toast. default delay will be 800ms
goAway : Function(delay = 800)
using the toast object
let myToast = this.$toasted.show("Holla !!");
myToast.text("Changing the text !!!").goAway(1500);
below are the available options
Option | Description | Values | Default |
---|---|---|---|
position | position of the toast container | 'top-right', 'top-center', 'top-left', 'bottom-right', 'bottom-center', 'bottom-left' | 'top-right' |
duration | display time of the toast | in millisecond | null |
className | custom css class name of the toast | null | |
theme | theme of the toast you prefer | 'primary', 'outline', 'bubble' | 'primary' |
onComplete | on complete event of toast | a callback function | null |
you can register your global toasts under globalToasts
. they will be available globally for use in $toasted.global
.
take a look at the detailed example here
// Global Plugin Register
Vue.use(Toasted, {
globalToasts : {
myGlobalToast : function(payload, initiate){
// your logic using payload here...
// this will initiate the toast
return initiate("My Deepest Condolence", 'error');
},
// my another toast...
}
});
viola !! now you can use your toast in anywhere
// send your payload to global toast
$toasted.global.myGlobalToast(payload);
- Whoever contributes to this project 😉
- Inspired and developed from materialize-css toast.
Enjoy Toasting !!