Alert.vue 797 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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: ['show'],
  10. data() {
  11. return {
  12. top: 100
  13. }
  14. },
  15. mounted() {
  16. console.log(this)
  17. // this.$page.alert = this.$page.alert ? this.$page.alert : {top: 100}
  18. // this.$page.alert.top += 20
  19. // this.top = this.$page.alert.top
  20. setTimeout(() => {
  21. this.$el.remove()
  22. }, 1000)
  23. }
  24. }
  25. </script>
  26. <style scoped>
  27. .alert{
  28. position: absolute;
  29. padding: 6px 8px;
  30. background-color: #f0f2f5;
  31. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  32. border-radius: 4px;
  33. margin: 0 auto;
  34. z-index: 999;
  35. top: 100px;
  36. width: fit-content;
  37. left: 0;
  38. right: 0;
  39. }
  40. </style>