toast.vue 976 B

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