custom-toast.vue 871 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <view class="custom-toast" v-if="visible">
  3. {{ message }}
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name:'CustomToast',
  9. data() {
  10. return {
  11. visible: false,
  12. message: '',
  13. duration: 1500,
  14. fontSize: '16px' // 可配置字体大小
  15. };
  16. },
  17. methods: {
  18. show(options) {
  19. this.message = options.title || '';
  20. this.duration = options.duration || 1500;
  21. this.fontSize = options.fontSize || '16px';
  22. this.visible = true;
  23. setTimeout(() => {
  24. this.visible = false;
  25. }, this.duration);
  26. }
  27. }
  28. };
  29. </script>
  30. <style>
  31. .custom-toast {
  32. position: fixed;
  33. top: 50%;
  34. left: 50%;
  35. transform: translate(-50%, -50%);
  36. padding: 12px 24px;
  37. background-color: rgba(0, 0, 0, 0.7);
  38. color: white;
  39. border-radius: 4px;
  40. font-size: 16px; /* 默认字体大小 */
  41. z-index: 9999;
  42. }
  43. </style>