toast.vue 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <v-snackbar
  3. app
  4. centered
  5. class="toast"
  6. :value.sync="value"
  7. color="rgba(0,0,0,.8)"
  8. v-bind="attrs"
  9. @input="!$event && destroy()"
  10. >
  11. <v-icon v-if="icon" left>{{ icon }}</v-icon>
  12. <span>{{ message }}</span>
  13. </v-snackbar>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'Toast',
  18. props: {
  19. message: {
  20. type: String,
  21. default: '',
  22. },
  23. icon: {
  24. type: String,
  25. default: '',
  26. },
  27. },
  28. data() {
  29. return {
  30. value: false,
  31. };
  32. },
  33. computed: {
  34. attrs() {
  35. return Object.entries(this.$options.propsData).reduce(
  36. (o, [key, value]) => {
  37. !Object.prototype.hasOwnProperty.call(this.$props, key) && (o[key] = value);
  38. return o;
  39. },
  40. {},
  41. );
  42. },
  43. },
  44. mounted() {
  45. this.$parent.$el.append(this.$el);
  46. this.value = true;
  47. },
  48. destroyed() {
  49. this.$el.remove();
  50. },
  51. methods: {
  52. destroy() {
  53. setTimeout(() => this.$destroy(), 1000);
  54. },
  55. },
  56. };
  57. </script>