toast.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view v-if="show" class="toast_body" :style="{'background-color': isMask ? 'rgba(0,0,0,.6)' : ''}">
  3. <slot></slot>
  4. <image v-if="isClose" class="close" src="../static/icon/close.png" @click="show = false"></image>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. props: {
  10. isShow: {
  11. type: Boolean,
  12. default: false
  13. },
  14. isMask: {
  15. type: Boolean,
  16. default: true
  17. },
  18. isClose: {
  19. type: Boolean,
  20. default: true
  21. },
  22. beforeClose: {
  23. type: Function,
  24. default: null
  25. }
  26. },
  27. watch: {
  28. isShow(a,b) {
  29. this.show = a
  30. },
  31. show(a, b) {
  32. if(!a) {
  33. if(this.beforeClose) {
  34. this.beforeClose.bind(this.$parent)()
  35. }
  36. }
  37. }
  38. },
  39. data() {
  40. return {
  41. show: this.isShow
  42. }
  43. }
  44. }
  45. </script>
  46. <style scoped lang="scss">
  47. .toast_body {
  48. position: fixed;
  49. z-index: 999999;
  50. top: 0;
  51. left: 0;
  52. bottom: 0;
  53. right: 0;
  54. width: 100%;
  55. height: 100%;
  56. display: flex;
  57. justify-content: center;
  58. flex-direction: column;
  59. .close{
  60. display: block;
  61. width: 62rpx;
  62. height: 62rpx;
  63. margin: 32rpx auto;
  64. }
  65. }
  66. </style>