Skip to content

Instantly share code, notes, and snippets.

@andreas-it-dev
Last active November 8, 2020 11:11
Show Gist options
  • Save andreas-it-dev/909b5a3629034505e24170cb5a3cfe37 to your computer and use it in GitHub Desktop.
Save andreas-it-dev/909b5a3629034505e24170cb5a3cfe37 to your computer and use it in GitHub Desktop.
Vuetify notification compononent
export const state = {
type: "blue-grey",
message: "",
timeout: 3000,
show: false
};
export const mutations = {
SHOW_NOTIFICATION(state, notification) {
state.type = notification.type;
state.message = notification.message;
if (notification.type && notification.message) {
state.show = true;
}
if (notification.timeout) {
state.timeout = notification.timeout;
}
},
};
export const actions = {
showNotification({ commit }, notification) {
commit("SHOW_NOTIFICATION", notification);
}
};
<template>
<div class="text-center">
<v-snackbar
v-model="notification.show"
:timeout="notification.timeout"
:color="notification.type"
>
{{ notification.message }}
<template v-slot:action="{ attrs }">
<v-btn dark text v-bind="attrs" @click="notification.show = false">
Close
</v-btn>
</template>
</v-snackbar>
</div>
</template>
<script>
import { mapState } from "vuex";
export default {
name: "Notification",
computed: {
...mapState(["notification"])
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment