popup.nvue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div class="wrapper">
  3. <text class="title">{{title}}</text>
  4. <scroller class="scroller">
  5. <div>
  6. <text class="content">{{content}}</text>
  7. </div>
  8. <div>
  9. <text style="color: red; font-size: 30rpx;">以下为 Popup 内部滚动示例:</text>
  10. </div>
  11. <div class="cell" v-for="(item, index) in lists" @click="handle(item)" :key="index">
  12. <text class="text">{{item}}</text>
  13. </div>
  14. </scroller>
  15. <div class="message-wrapper">
  16. <text class="send-message" @click="sendMessage">向页面发送消息</text>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. title: '',
  25. content: '',
  26. lists: [],
  27. }
  28. },
  29. created() {
  30. const vm = this;
  31. for (let i = 1; i < 20; i++) {
  32. this.lists.push('item' + i);
  33. }
  34. uni.$on('page-popup', (data) => {
  35. vm.title = data.title;
  36. vm.content = data.content;
  37. })
  38. },
  39. beforeDestroy() {
  40. uni.$off('drawer-page')
  41. },
  42. methods: {
  43. sendMessage() {
  44. const subNVue = uni.getCurrentSubNVue()
  45. uni.$emit('popup-page', {
  46. title: '已读完!',
  47. })
  48. },
  49. handle(item, index) {
  50. const subNVue = uni.getCurrentSubNVue()
  51. uni.$emit('popup-page', {
  52. type: 'interactive',
  53. info: item + ' 该元素被点击了!',
  54. })
  55. }
  56. }
  57. }
  58. </script>
  59. <style>
  60. .wrapper {
  61. flex-direction: column;
  62. justify-content: space-between;
  63. padding: 10rpx 15rpx;
  64. background-color: #F4F5F6;
  65. border-radius: 4rpx;
  66. }
  67. .title {
  68. height: 100rpx;
  69. line-height: 100rpx;
  70. border-bottom-style: solid;
  71. border-bottom-width: 1rpx;
  72. border-bottom-color: #CBCBCB;
  73. flex: 0;
  74. font-size: 30rpx;
  75. }
  76. .scroller {
  77. height: 400rpx;
  78. padding: 8rpx 15rpx;
  79. }
  80. .content {
  81. color: #555555;
  82. font-size: 32rpx;
  83. }
  84. .message-wrapper {
  85. flex: 0;
  86. border-top-style: solid;
  87. border-top-width: 1rpx;
  88. border-top-color: #CBCBCB;
  89. height: 80rpx;
  90. align-items: flex-end;
  91. }
  92. .send-message {
  93. font-size: 30rpx;
  94. line-height: 80rpx;
  95. color: #00CE47;
  96. margin-left: 20rpx;
  97. }
  98. .cell {
  99. margin: 10rpx;
  100. padding: 20rpx 0;
  101. top: 10rpx;
  102. align-items: center;
  103. justify-content: center;
  104. border-radius: 10rpx;
  105. background-color: #5989B9;
  106. }
  107. .text {
  108. font-size: 30rpx;
  109. text-align: center;
  110. color: white;
  111. }
  112. </style>