Last active
November 8, 2020 11:11
-
-
Save andreas-it-dev/909b5a3629034505e24170cb5a3cfe37 to your computer and use it in GitHub Desktop.
Vuetify notification compononent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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