Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify Snackbar disappears after x seconds, how to prevent that

Somehow my vuetify Snackbar disappears after 6 seconds I am trying to Prevent that but I fail. This is how my vue component Looks like it is basically a Snackbar with additional Buttons.

<template>
    <div>
        <v-snackbar
            :timeout="timeout"
            :bottom="'bottom'"
            :right="'right'"
            :auto-height="true"
            v-model="googleAnalyticsSnackbar"
        >
            {{ text }}
             <v-btn flat color="pink">
                 <a href="#">test</a>
            </v-btn>
            <v-btn flat color="pink" @click.native="googleAnalyticsSnackbar = false">yes</v-btn>
            <v-btn flat color="pink" @click.native="googleAnalyticsSnackbar = false">no</v-btn>
        </v-snackbar>
    </div>      
</template>

<script>
    export default {

        mounted() {
            if(this.checkCookieStatus() == false || this.checkCookieStatus() == null) {
                this.googleAnalyticsSnackbar = true;
            }
        },

        data: () => ({
            googleAnalyticsSnackbar: true,
            timeout: 0,
            text: 'foo'
        }),

        methods: {
            acceptCookie() {
                this.$cookie.set('cookie_accept_status', true, 1);
            },

            declineCookie() {
                this.$cookie.set('cookie_accept_status', false, 1);
            },

            checkCookieStatus() {
                return this.$cookie.get('cookie_accept_status');
            }
        }

    };
</script>

I call it like this in my main js file:

Vue.component('google-analytics-cookie', require('./components/GoogleAnalyticsCookieToastComponent.vue'));

and include it like this in my html:

        <google-analytics-cookie></google-analytics-cookie>

but the Snackbar just dissapears after ~6 seconds, the docs say that 0 should Prevent that from Happening but it wont work.

like image 544
tigerel Avatar asked Jan 28 '23 01:01

tigerel


1 Answers

The problem is with the bottom and right attribute bindings:

:bottom="'bottom'"
:right="'right'"

Those should be true or false instead of strings.

It should work just as the docs describe otherwise. Example:

new Vue({
  el: '#app',
  data () {
    return {
      snackbar: true,
      timeout: 0,
      bottom: true,
      right: true
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.3.12/vuetify.min.js" integrity="sha256-MDwft2SRPd5GCJGWRIbkS5l7Gcr3S3vJr7MKpe1Z3+Q=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.3.12/vuetify.min.css" integrity="sha256-h8aOnZm3FeYz5m4z7eI3xc0uJX3l/mF+0i2643O7ieM=" crossorigin="anonymous" />

<div id="app">
  <v-app>
    <v-snackbar :timeout="timeout" v-model="snackbar" :bottom="bottom" :right="right" color="indigo">Hi There <v-btn @click="snackbar=false" dark>Close</v-btn></v-snackbar>
  </v-app>
</div>
like image 81
Brian Lee Avatar answered May 05 '23 17:05

Brian Lee