Skip to content

Instantly share code, notes, and snippets.

@b4n92uid
Created January 3, 2020 16:50
Show Gist options
  • Save b4n92uid/0c7a1a940c3e9e79b82a8c50bcdf20c2 to your computer and use it in GitHub Desktop.
Save b4n92uid/0c7a1a940c3e9e79b82a8c50bcdf20c2 to your computer and use it in GitHub Desktop.
[Vuetify] Notifier
<template>
<v-snackbar
:timeout="4000"
left
bottom
:value="!empty"
@input="pop"
:color="current.type"
light
>
{{ current.message }}
<v-btn color="white" text @click.native="pop">Fermer</v-btn>
</v-snackbar>
</template>
<script>
export default {
data() {
return {
list: []
};
},
computed: {
empty() {
return this.list.length === 0;
},
current() {
if (this.empty)
return {
message: null,
type: null
};
else return this.list[0];
}
},
methods: {
push(error, type = "info") {
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
error.graphQLErrors.forEach(e =>
this.list.push({ message: e.message, type })
);
} else if (error.message) {
this.list.push({ message: error.message, type });
} else {
this.list.push({ message: error, type });
}
},
pop() {
this.list.shift();
}
}
};
</script>
<style></style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment