Search results

Restrict the maximum toast to show in Vue Toast component

You can restrict the maximum toast count by using the event callback function and terminate the toast displaying process by setting the cancel event property in the beforeOpen event.

The following sample demonstrates restricting toast displaying up to 3. You can restrict by your own count with custom code blocks.

   <div id='app'>
        <ejs-button ref='showButtonRef' class="e-btn" id="show_toast" v-on:click.native="showBtnClick">Show Toast</ejs-button>
        <ejs-toast ref='elementRef' id='element' title='Sample Toast Title' content='Sample Toast content' :position='position' :beforeOpen='beforeOpen'></ejs-toast>

import Vue from "vue";
import { ToastPlugin, Toast } from "@syncfusion/ej2-vue-notifications";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
export default {
  name: 'app',
  data: function(){
        return {
            position: { X: 'Right', Y: 'Bottom' }
  mounted: function() {
      this.toastFlag = 0;
      this.maxCount = 3;
      this.toasts = [
               { title: 'Warning !', content: 'There was a problem with your network connection.' },
               { title: 'Success !', content: 'Your message has been sent successfully.' },
               { title: 'Error !', content: 'A problem has been occurred while submitting your data.' },
               { title: 'Information !', content: 'Please read the comments carefully.' }];
  methods: {
       showBtnClick: function(args){
           if (this.toastFlag === (this.toasts.length)) {
               this.toastFlag = 0;
       beforeOpen: function(e){
          if (this.maxCount === this.$refs.elementRef.ej2Instances.element.childElementCount) {
               e.cancel =true;
          } else {
               e.cancel = false;
@import '../../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-vue-buttons/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-vue-popups/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-vue-notifications/styles/material.css';