All Projects → ahmed-dinar → Vuex Flash

ahmed-dinar / Vuex Flash

Licence: mit
VueJs Flash Message Component within Vuex

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vuex Flash

Vue Cnode
基于vue2 + vue-router + vuet + ES6 + less + flex.css重写vue版cnode社区,使用webpack2打包
Stars: ✭ 1,134 (+2000%)
Mutual labels:  vuex, vuex2, vue-components, vuejs2, vue2
Vue Chat
👥Vue全家桶+Socket.io+Express/Koa2打造一个智能聊天室。
Stars: ✭ 887 (+1542.59%)
Mutual labels:  vuex, vuex2, vuejs2, vue2
Vue Objccn
🔥 Use Vue.js to develop a cross-platform full stack application / 用 Vue.js 开发的跨三端应用
Stars: ✭ 1,993 (+3590.74%)
Mutual labels:  vuex, vue-components, vuejs2, vue2
Vuemmerce
👉 Responsive ecommerce template 🛒 built with Vue.js and Nuxt.js
Stars: ✭ 223 (+312.96%)
Mutual labels:  vuex, vue-components, vuejs2, vue2
Vue Entity Adapter
Package to maintain entities in Vuex.
Stars: ✭ 20 (-62.96%)
Mutual labels:  vuex, vuex2, vuejs2, vue2
Vue Cnode
🔥Vue.js打造一个开源的CNode社区。CNode by Vue.js
Stars: ✭ 249 (+361.11%)
Mutual labels:  vuex, vuex2, vuejs2, vue2
Vuesax
New Framework Components for Vue.js 2
Stars: ✭ 5,293 (+9701.85%)
Mutual labels:  vue-components, vuejs2, vue2
Cordova Template Framework7 Vue Webpack
Framework7 - Vue - Webpack Cordova Template with Webpack Dev Server and Hot Module Replacement
Stars: ✭ 630 (+1066.67%)
Mutual labels:  vuex, vuejs2, vue2
Vue Music Player
🎵Vue.js写一个音乐播放器+📖One(一个).A music player + One by Vue.js
Stars: ✭ 729 (+1250%)
Mutual labels:  vuex, vuejs2, vue2
Vue Quill Editor
🍡@quilljs editor component for @vuejs
Stars: ✭ 6,874 (+12629.63%)
Mutual labels:  vue-components, vuejs2, vue2
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (+720.37%)
Mutual labels:  vue-components, vuejs2, vue2
Vue Snotify
Vuejs 2 Notification Center
Stars: ✭ 755 (+1298.15%)
Mutual labels:  vue-components, vuejs2, vue2
Vue Meteor
🌠 Vue first-class integration in Meteor
Stars: ✭ 893 (+1553.7%)
Mutual labels:  vuex, vue-components, vuejs2
Vue Share Buttons
🔗A set of social buttons for Vue.js
Stars: ✭ 34 (-37.04%)
Mutual labels:  vue-components, vuejs2, vue2
Vuelayers
Web map Vue components with the power of OpenLayers
Stars: ✭ 532 (+885.19%)
Mutual labels:  vue-components, vuejs2, vue2
Vuex I18n
Localization plugin for vue.js 2.0 using vuex as store
Stars: ✭ 657 (+1116.67%)
Mutual labels:  vuex, vuejs2, vue2
Dashboard
A dashboard scaffolding based on Vue.js 3.0 created by Vite.
Stars: ✭ 497 (+820.37%)
Mutual labels:  vuex, vuejs2, vue2
Manhuaren
vue2.0全家桶,仿漫画人官网(移动端)
Stars: ✭ 18 (-66.67%)
Mutual labels:  vuex, vuex2, vuejs2
Vms
A Vue.js 2.0 Content Management System
Stars: ✭ 885 (+1538.89%)
Mutual labels:  vuex, vuejs2, vue2
Vue Image Loader
Vue progressive image loader plugin like Medium
Stars: ✭ 47 (-12.96%)
Mutual labels:  vue-components, vuejs2, vue2

Vuex Flash

Flash message component for Vue.js within Vuex

Vue.js 2.x compatible Vuex 2.x compatible travis-ci build circleci build coveralls npm package dependency code quality license

Features

Demo & Example

Live demo with code snippet

Install

$ npm install --save vuex-flash

Usage

register component:

//main.js

import Vue from 'vue';
import VuexFlash from 'vuex-flash';

Vue.use(VuexFlash);

register vuex store:

//store.js

import { createFlashStore } from 'vuex-flash';

const store = new Vuex.Store({
  // ...
  plugins: [
    createFlashStore()
  ]
});

Flash data

Using global mixin

Simply put an option mixin: true while registering component, the this.flash method will avaiable in every component

Vue.use(VuexFlash, { mixin: true });

Then in other components:

this.flash({ message: 'some message', variant: 'success' });
this.$router.push('/somepage'); //redirect to /somepage

You can change the method name:

Vue.use(VuexFlash, { mixin: true, method: 'flashMe' });
//now
this.flashMe({ message: 'some message', variant: 'success' });
about global mixin
Using mutation

Instead of global mixin, you can commit mutation from components to set flash message:

methods: {
  //...
  someMethod(){
    //..
    this.$store.commit('FLASH/SET_FLASH', { message: 'some message', variant: 'success' });
  }
}

In mapMutations way:

methods: {
  //...
  someMethod(){
    //..
    this.flash({ message: 'some message', variant: 'success' });
  },

  ...mapMutations({
    flash: 'FLASH/SET_FLASH'
  })
}

Note that the default mutation type is FLASH/SET_FLASH. You can configure it in options.

Display flash

//in somepage component

<template>
  <flash-message variant="success"></flash-message>
  //......
</template>

Multiple flash

this.flash({ message: 'some success message', variant: 'success' });
this.flash({ message: 'some warning message', variant: 'warning' });
this.flash({ message: 'some danger message', variant: 'danger' });
this.$router.push('/somepage'); //redirect to /somepage
//in somepage
<flash-message variant="success"></flash-message>
<flash-message variant="danger"></flash-message>
<flash-message variant="warning"></flash-message>

Props

Name Type Default Desciption
variant String - required prop.the flash variant type
important Boolean false if true, there will no close option of flash alert
autoHide Boolean false auto hide flash alert
transitionName String custom-classes-transition vue transitions name prop More
transitionIn String 'animated fadeInDown' space separted string for vue transitions enter-active-class prop More
transitionOut String 'animated fadeOutUp' space separted string for vue transitions leave-active-class prop More

Flash alert style

vuex-flash uses Bootstrap v4 alert component as default alert.You need to add bootstrap css file in your head tag.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">

You can always use your own alert using custom template.

Variant

The Default variant types are:

  • success
  • warning
  • danger
  • info

You can add custom variants.

Transition

vuex-flash uses animate.css as default transition effect.You need to add the css file in your head tag

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">

You can set different animation style using transitionIn and transitionOut props in multiple flash messages:

<flash-message variant="success" transitionIn="animated bounceIn" transitionOut="animated bounceOut"></flash-message>
<flash-message variant="danger" transitionIn="animated flipInX" transitionOut="animated flipOutX"></flash-message>

If you choose to use custom template, then you need to add this feature yourself if you want.

Custom Template

  • The default template can be found here.
  • Put {{ message }} inside your template where you want to show the flash message.
  • Use v-if="show" to show the alert.
  • The cssClasses string data will be all classes including variant class and your custom classes that you provide in options. Bind class :class="cssClasses"
  • Use closeFlash method to trigger the close button click.
  • Here is an example that showing the implementation of custom template of Bulma notification

Persist Flash message

API

Vue.use(VuexFlash, [options]);

The following options are available to configure the component plugin:

  • name [String] - The component name. (default: 'FlashMessage')

  • mixin [Boolean] - If true, an global method mixin will register for setting flash data. (default: false)

  • method [String] - If mixin is set true and this option is given, then global mixin method will register under this name. (default: 'flash')

  • namespace - [String] - The namespace is the name used for creating vuex flash module.This should be same as the createFlashStore namespace. this namespace used for commiting mutation to set and clear flash data. If provided, the mutation type will be '{namespace}/SET_FLASH'. (default: 'FLASH')

  • duration [Number] - The flash message display duration (in milliseconds) for auto hide flashes. (default: 3000)

  • template [String] - The template to use showing alert. See custom template.

  • keep [Boolean] - If false and data is persisted in storage, the storage will cleared after displaying alert every time. if provided, the storage will keep with null value. (default: true)

  • storage [Storage] - The Storage where the data is persisted. If keep is set to false, the data will be cleared from this storage. (default: sessionStorage)

  • key [String] - The key is used by the store to persist data. (default: '__vuexFlash')

  • css [Array] - An array of custom css class names. This is very useful when creating custom template. (default: [])

  • variantClass [Function] - A function returns a css class name to styling alert component based on current variant. .Can access the current variant using this.variant. Do not use arrow function.
    (default: function(){ return `alert-${this.variant}`; })

  • clearPersisted [Function] - A function used for clearing persisted data from storage when keep is set to false.Can access the storage using this.storage. Do not use arrow function.
    (default: function(){ this.storage.removeItem(this.key); })

createFlashStore([options])

The following options are available to configure the vuex store plugin:

  • namespace [String] - This namespace is the name used for registering the vuex-flash store module. (default: 'FLASH')

  • setter [String] - This is the mutation name of flash message setter.If provided, the mutation key will be '${namespace}/${setter}'. (default: 'SET_FLASH')

  • variants [Array] - An array of Custom variants to use as state.Will be merged with default variants. (default: [])

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].