custom-popup-example.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="example">
  3. <button class="btn" @click="openPopupBottom">底部弹出</button>
  4. <button class="btn" @click="openPopupCenter">中间弹出</button>
  5. <button class="btn" @click="openPopupTop">顶部弹出</button>
  6. <button class="btn" @click="openPopupLeft">左侧弹出</button>
  7. <button class="btn" @click="openPopupRight">右侧弹出</button>
  8. <!-- 底部弹出示例 -->
  9. <custom-popup v-model="showBottom" mode="bottom" @close="closeBottom">
  10. <view class="popup-content">
  11. <view class="popup-title">底部弹出</view>
  12. <view class="popup-text">这是一个底部弹出的示例</view>
  13. <button class="popup-btn" @click="closeBottom">关闭弹窗</button>
  14. </view>
  15. </custom-popup>
  16. <!-- 中间弹出示例 -->
  17. <custom-popup v-model="showCenter" mode="center" border-radius="20" @close="closeCenter">
  18. <view class="popup-content">
  19. <view class="popup-title">中间弹出</view>
  20. <view class="popup-text">这是一个中间弹出的示例</view>
  21. <button class="popup-btn" @click="closeCenter">关闭弹窗</button>
  22. </view>
  23. </custom-popup>
  24. <!-- 顶部弹出示例 -->
  25. <custom-popup v-model="showTop" mode="top" @close="closeTop">
  26. <view class="popup-content">
  27. <view class="popup-title">顶部弹出</view>
  28. <view class="popup-text">这是一个顶部弹出的示例</view>
  29. <button class="popup-btn" @click="closeTop">关闭弹窗</button>
  30. </view>
  31. </custom-popup>
  32. <!-- 左侧弹出示例 -->
  33. <custom-popup v-model="showLeft" mode="left" @close="closeLeft">
  34. <view class="popup-content">
  35. <view class="popup-title">左侧弹出</view>
  36. <view class="popup-text">这是一个左侧弹出的示例</view>
  37. <button class="popup-btn" @click="closeLeft">关闭弹窗</button>
  38. </view>
  39. </custom-popup>
  40. <!-- 右侧弹出示例 -->
  41. <custom-popup v-model="showRight" mode="right" @close="closeRight">
  42. <view class="popup-content">
  43. <view class="popup-title">右侧弹出</view>
  44. <view class="popup-text">这是一个右侧弹出的示例</view>
  45. <button class="popup-btn" @click="closeRight">关闭弹窗</button>
  46. </view>
  47. </custom-popup>
  48. </view>
  49. </template>
  50. <script>
  51. import CustomPopup from './custom-popup.vue';
  52. export default {
  53. components: {
  54. CustomPopup
  55. },
  56. data() {
  57. return {
  58. showBottom: false,
  59. showCenter: false,
  60. showTop: false,
  61. showLeft: false,
  62. showRight: false
  63. }
  64. },
  65. methods: {
  66. // 底部弹出
  67. openPopupBottom() {
  68. this.showBottom = true;
  69. },
  70. closeBottom() {
  71. this.showBottom = false;
  72. },
  73. // 中间弹出
  74. openPopupCenter() {
  75. this.showCenter = true;
  76. },
  77. closeCenter() {
  78. this.showCenter = false;
  79. },
  80. // 顶部弹出
  81. openPopupTop() {
  82. this.showTop = true;
  83. },
  84. closeTop() {
  85. this.showTop = false;
  86. },
  87. // 左侧弹出
  88. openPopupLeft() {
  89. this.showLeft = true;
  90. },
  91. closeLeft() {
  92. this.showLeft = false;
  93. },
  94. // 右侧弹出
  95. openPopupRight() {
  96. this.showRight = true;
  97. },
  98. closeRight() {
  99. this.showRight = false;
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. .example {
  106. padding: 30rpx;
  107. .btn {
  108. margin-bottom: 20rpx;
  109. background-color: #38C148;
  110. color: #FFFFFF;
  111. }
  112. }
  113. .popup-content {
  114. padding: 30rpx;
  115. .popup-title {
  116. font-size: 32rpx;
  117. font-weight: bold;
  118. margin-bottom: 20rpx;
  119. text-align: center;
  120. }
  121. .popup-text {
  122. font-size: 28rpx;
  123. color: #666;
  124. margin-bottom: 30rpx;
  125. text-align: center;
  126. }
  127. .popup-btn {
  128. background-color: #38C148;
  129. color: #FFFFFF;
  130. border-radius: 10rpx;
  131. font-size: 28rpx;
  132. }
  133. }
  134. </style>