# vue-flash-message
[](https://vuejs.org/index.html)
[](https://github.com/smwbtech/vue-flash-message/blob/master/LICENSE.md)
[](https://travis-ci.org/smwbtech/vue-flash-message)
[](https://coveralls.io/github/smwbtech/vue-flash-message?branch=master)
[](https://bundlephobia.com/result?p=@smartweb/vue-flash-message@latest)

The component to display single flash message or multiple flash messages to user. It has styles presets, but can be easily customized by passing style object as argument.
#### [Live Demo](https://smwbtech.github.io/vue-flash-message/)
#### [Docs](https://smwb-tech.gitbook.io/vue-flash-message/)
## Setup
```
npm i @smartweb/vue-flash-message
```
## Installation and Configuration
Register the component in your app entry point (main.js or as you called it)
```javascript
import Vue from 'vue';
import FlashMessage from '@smartweb/vue-flash-message';
Vue.use(FlashMessage);
```
You can pass [configuration object](#configuration-object) as second argument
```javascript
Vue.use(FlashMessage, config);
```
### Nuxt.js
Create vue-flash-message.js file in plugins directory and put the following code:
```javascript
import Vue from 'vue';
import VueFlashMessage from '@smartweb/vue-flash-message';
Vue.use(VueFlashMessage);
```
In your nuxt.config.js file register your plugin
```javascript
{
/* Since Nuxt.js 2.4, mode has been introduced as option of plugins to specify plugin type, possible value are: client or server. ssr: false will be adapted to mode: 'client' and deprecated in next major release.
More info: https://nuxtjs.org/guide/plugins#client-side-only */
plugins: [{ src: '~/plugins/flash-message.js', mode: 'client' }]
},
```
### Configuration object
---
| Property | Type | Description | Default |
| ------------ | ---------- | ------------------------------------------------------------------------------------------------- | -------------- |
| **name** | **String** | It is a name of the component and alias for the EventBus global property. | 'flashMessage' |
| **tag** | **String** | Custom tag for the component to use in your application. | 'FlashMesage' |
| **time** | **Number** | Duration (in ms) of the message display (can be customized during message call). | 8000 |
| **strategy** | **String** | You can pass 'single' or 'multiple' to choose the default strategy. It can be changed in process. | 'single' |
## Usage
Put the component into your template
```html
{{ text }}
``` For example you can add some sound which will be played when message appears ```javascript methods: { showText() { this.text = 'Hello from callback!' }, clearText() { this.text = 'Bye... 1, ..2, ..3'; let sound = new Audio('audio source'); // add sound source sound.play(); // and play it setTimeout( () => this.text = '', 3000); }, clickHandler() { this.flashMessage.info({ title: 'Ooooooops!', message: 'Do you see this text and hear this sound? Wtf?' }, { mounted: showText, destroyed: clearText }) } } ``` ### Delete Methods --- You can delete message programmatically using deleteMessage method **Example:** ```javascript let id = this.flashMessage.info({ title: 'Hey, man. Time for beer!', message: 'It is Friday. Time to have a little party.' }); this.flashMessage.deleteMessage(id); ``` ### Set Strategy --- You can update default strategy using setStrategy method. ```javascript /* Will return {Boolean} as result */ this.flashMessage.setStrategy('multiple'); // strategy changed to multiple ``` ## LICENSE The MIT License (MIT). Please see [License File](LICENSE.md) for more information.