RemindBox.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div class="com-remind-box" v-show="showBox">
  3. <div>{{title}}</div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. props: ['title', 'timeoutCount'],
  9. data () {
  10. return {
  11. showBox: false,
  12. timer: ''
  13. }
  14. },
  15. watch: {
  16. timeoutCount: function (val, oldVal) {
  17. if (val > 0) {
  18. clearTimeout(this.timer)
  19. this.setTimer()
  20. } else {
  21. this.showBox = false
  22. }
  23. }
  24. },
  25. methods: {
  26. setTimer: function () {
  27. let _this = this
  28. _this.showBox = true
  29. let timeout = 1000
  30. if (_this.title === '收藏成功' || _this.title === '取消成功') {
  31. timeout = 1000
  32. } else {
  33. timeout = 1500
  34. }
  35. _this.timer = setTimeout(function () {
  36. _this.showBox = false
  37. }, timeout)
  38. }
  39. }
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .com-remind-box{
  44. position: fixed;
  45. top: 50%;
  46. left: 0;
  47. right: 0;
  48. margin-top: -.6rem;
  49. z-index: 10000;
  50. div {
  51. background: rgba(0,0,0,.6);
  52. color: #fff;
  53. font-size: .28rem;
  54. padding: .44rem .51rem;
  55. border-radius: .1rem;
  56. width: max-content;
  57. margin: 0 auto;
  58. max-width: 70%;
  59. }
  60. }
  61. </style>