Alert.vue 799 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <div class="alert" :style="`top: ${top}px`">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'Alert',
  9. props: ['alert'],
  10. data() {
  11. return {
  12. top: 0
  13. }
  14. },
  15. beforeMount() {
  16. this.top = this.alert.top
  17. },
  18. mounted() {
  19. window.addEventListener('alert_remove', (e) => {
  20. this.top -= e.detail.height
  21. })
  22. },
  23. watch: {
  24. 'page.alert.top': function (value) {
  25. }
  26. }
  27. }
  28. </script>
  29. <style scoped>
  30. .alert{
  31. position: fixed;
  32. padding: 6px 8px;
  33. background-color: #fff;
  34. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
  35. border-radius: 4px;
  36. margin: 0 auto;
  37. z-index: 999;
  38. top: 100px;
  39. width: fit-content;
  40. left: 0;
  41. right: 0;
  42. transition: top 0.3s;
  43. }
  44. </style>