issues-16118.uvue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <scroll-view style="flex: 1;">
  3. <button @click="switchDisplay">显示内容</button>
  4. <view v-show="contentVisible" style="flex: 1;">
  5. <list-view style="height: 200px;">
  6. <sticky-section v-for="(group, _) in groupItems">
  7. <sticky-header style="background-color: antiquewhite;">
  8. <text class="group-title">{{ group.title }}</text>
  9. </sticky-header>
  10. <list-item class="content-group">
  11. <view class="content-box">
  12. <text class="item" v-for="index in 20" >{{index}} item信息</text>
  13. </view>
  14. </list-item>
  15. </sticky-section>
  16. </list-view>
  17. </view>
  18. </scroll-view>
  19. </template>
  20. <script>
  21. type ItemGroup = {
  22. title : string
  23. }
  24. export default {
  25. data() {
  26. return {
  27. groupItems: [] as ItemGroup[],
  28. contentVisible: false
  29. }
  30. },
  31. methods: {
  32. switchDisplay() {
  33. if (this.contentVisible) {
  34. this.contentVisible = false
  35. } else {
  36. this.contentVisible = true
  37. }
  38. if (this.contentVisible) {
  39. setTimeout(() => {
  40. this.groupItems = [{
  41. title: 'sticky-header'
  42. }] as ItemGroup[]
  43. }, 200)
  44. } else {
  45. setTimeout(() => { // 面板隐藏,释放内存
  46. this.groupItems = []
  47. }, 200)
  48. }
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss">
  54. .group-title {
  55. font-weight: bold;
  56. font-size: 14px;
  57. color: #4B515A;
  58. padding: 8px 0;
  59. background-color: #FFFFFF;
  60. }
  61. .content-group {
  62. flex-direction: row;
  63. flex-wrap: wrap;
  64. }
  65. .content-box {
  66. width: 100%;
  67. position: relative;
  68. }
  69. .item{
  70. padding: 10px 0;
  71. background-color: #efeda7;
  72. }
  73. </style>