ToastMessage.vue 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <v-card>
  3. <v-snackbar
  4. v-model="isVisible"
  5. :color="level"
  6. :timeout="timeout"
  7. multi-line
  8. >
  9. {{ text }}
  10. <v-btn
  11. dark
  12. flat
  13. @click="isVisible = false"
  14. >
  15. Close
  16. </v-btn>
  17. </v-snackbar>
  18. </v-card>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'ToastMessage',
  23. data() {
  24. return {
  25. text: '',
  26. level: 'success',
  27. timeout: 4000,
  28. isVisible: false
  29. }
  30. },
  31. methods: {
  32. /**
  33. * Briefly show a toast message
  34. *
  35. * @param {String} text toast to show
  36. * @param {('info'|'success'|'error')} [level='success'] toast type
  37. * @param {Number} [timeout=4000] amount of time the toast will be visible
  38. * @returns {void}
  39. */
  40. show(text, level = 'success', timeout = 4000) {
  41. this.text = text
  42. this.level = level
  43. this.timeout = timeout
  44. this.isVisible = true
  45. }
  46. }
  47. }
  48. </script>