Content.vue 1.2 KB

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