toast.vue 1.1 KB

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