# Notifications

Nice, simple, and interactive notifications.

# Notifications Defaults

To add a notification we have the global function $vs.notify. The first parameter is a json with all the necessary attributes, or if we only want the standard notification we can only add a string with the text of the notification.

# Positions

We can change the place where the notification appears with the property position. A practical example would be: position: 'top-right'. The supported values are:

  • top-right
  • top-left
  • bottom-left
  • bottom-center
  • top-center

:::warning The default notifications appear bottom-right, it is not necessary to add the position property if it is the desired position. :::

# Icons

Notifications can include icons to improve the user experience and to construct a more pleasant and intuitive notification. To make this, use the icon property. A practical example would be: icon: 'chat'. ::: tip Vuesax uses the Google Material Icons font library by default. For a list of all available icons, visit the official Material Icons page (opens new window). Other icon libraries can be used by providing the class for the respective pack in the icon-pack property. ex. FA4 uses fa or fas, FA5 uses fas, far, or fal. :::

<template lang="html">
  <div class="centerx">
    <vs-button @click="$vs.notify({title:'Icon mail',text:'Lorem ipsum dolor sit amet, consectetur',color:'primary',icon:'mail'})" color="primary" type="flat">Icon Mail</vs-button>
    <vs-button @click="$vs.notify({title:'Icon mail',text:'Lorem ipsum dolor sit amet, consectetur',color:'success',icon:'check_box'})" color="success" type="flat">Icon check_box</vs-button>
    <vs-button @click="$vs.notify({title:'Icon mail',text:'Lorem ipsum dolor sit amet, consectetur',color:'danger',icon:'favorite'})" color="danger" type="flat">Icon favorite</vs-button>
    <vs-button @click="$vs.notify({title:'Icon mail',text:'Lorem ipsum dolor sit amet, consectetur',color:'warning',icon:'error'})" color="warning" type="flat">Icon error</vs-button>
    <vs-button @click="$vs.notify({title:'Icon mail',text:'Lorem ipsum dolor sit amet, consectetur',color:'dark',icon:'chat'})" color="dark" type="flat">Icon chat</vs-button>
    <vs-button @click="randomIcon()" color="success" type="gradient">Icon Random Color</vs-button>
  </div>
</template>

<script>
export default {
  methods:{
    randomIcon(){
      function getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min)) + min;
      }
      let color = `rgb(${getRandomInt(0,255)},${getRandomInt(0,255)},${getRandomInt(0,255)})`

      this.$vs.notify({title:'Icon mail',text:'Lorem ipsum dolor sit amet, consectetur',color:color,icon:'verified_user'})
    }
  }
}
</script>

# Fixed and function click

Sometimes we need to execute a function when the user clicks on the notification. For this, pass a function to the click property. Example: click:()=>{ ... }

# Time

You can change the total time that the notification stays on the screen with the time property. Example: time: 4000.

::: tip By default the notifications have a time of 2000 (2s) :::

API #

Name Type Parameters Description default
$vs.notify function (title,text,color,position,icon,click,fixed) Function that makes the notification appear.
title string Title of the notification.
time Number Waiting time for notification to disappear. 2s
text string Notification text.
color string RGB, HEX, primary, success, danger, warning, dark Background color of the notification.
position string bottom-right, top-right, top-left, bottom-left, bottom-center, top-center Position in which the notification appears.
icon string Material Icon Notification Icon.
icon-pack String Icon Pack Class Name Icon Pack to be used. If not set, icon will default to Material Icons. ex. FA4 uses fa or fas, FA5 uses fas, far, or fal. material-icons
click Function function(){ ... }, ()=>{ ... } Function executed by clicking on the notification
fixed Boolean true, false Removes the automatic elimination of the notification