Content.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <v-alert
  3. v-model="show"
  4. :type="alert.type"
  5. class="position"
  6. border="left"
  7. width="400"
  8. dismissible
  9. transition="fade-transition"
  10. @mouseover="onMouseOver"
  11. @mouseout="onMouseOut"
  12. >
  13. {{ $t(alert.message) }}
  14. </v-alert>
  15. </template>
  16. <script lang="ts">
  17. import { defineComponent, ref, Ref } from '@vue/composition-api'
  18. import { useContext } from '@nuxtjs/composition-api'
  19. import { alert } from '~/types/interfaces'
  20. export default defineComponent({
  21. props: {
  22. alert: {
  23. type: Object as () => alert,
  24. required: true
  25. }
  26. },
  27. setup () {
  28. const { store } = useContext()
  29. const show:Ref<boolean> = ref(true)
  30. let timeout: any = null
  31. const clearAlert = (time:number = 2000) => {
  32. timeout = setTimeout(() => {
  33. show.value = false
  34. store.dispatch('page/removeSlowlyAlert')
  35. }, time)
  36. }
  37. const onMouseOver = () => {
  38. clearTimeout(timeout)
  39. }
  40. const onMouseOut = () => {
  41. clearAlert(1000)
  42. }
  43. clearAlert()
  44. return {
  45. show,
  46. onMouseOver,
  47. onMouseOut
  48. }
  49. }
  50. })
  51. </script>
  52. <style scoped>
  53. </style>