当前位置:   article > 正文

uniapp分类列表(简易)_商品列表分类代码uniapp

商品列表分类代码uniapp
  1. <template>
  2. <view class="containar">
  3. <!-- 案例分享 -->
  4. <view class="typeAndList">
  5. <scroll-view class="type" scroll-y="true" :style="{ height: wh + 'px' }">
  6. <!-- <view class="type"> -->
  7. <view class="typeItem" :class="checkId == item.id ? 'checked' : ''" v-for="item in typeList" :key="item.id"
  8. @click="choose(item.id)">
  9. <view class="active" v-show="checkId == item.id"></view>
  10. <view class="item">{{ item.label }}</view>
  11. </view>
  12. <!-- </view> -->
  13. </scroll-view>
  14. <scroll-view scroll-y="true" class="list" :style="{ height: wh + 'px' }" :scroll-top="scrollTop">
  15. <view class="typeItemBox" v-for="(item2, i2) in cateLevel2" :key="i2">
  16. <view class="typeName">{{ item2.name }}</view>
  17. <view class="boxList">
  18. <view class="box" v-for="(item3, i3) in item2.children" :key="i3">
  19. <view style="width: 162rpx;
  20. height: 162rpx;border: 2rpx solid red;"></view>
  21. <!-- <img src="@/static/imgs/mpbg.jpg" alt=""> -->
  22. <view class="contBox">
  23. <view class="title">{{ item3.name }}</view>
  24. <view class="intro">{{ item3.detail }}</view>
  25. <view class="btnBox">
  26. <view class="btn">查看</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. // 当前设备可用的高度
  41. wh: 0,
  42. scrollTop: 0,
  43. typeList: [
  44. {
  45. label: '案例类型', id: '1',
  46. children: [
  47. {
  48. name: '港珠澳大桥1',
  49. children: [
  50. { name: '港珠澳大桥', detail: '这个项目非常好……' },
  51. { name: '港珠澳大桥', detail: '这个项目非常好……' },
  52. ]
  53. },
  54. ]
  55. },
  56. {
  57. label: '案例类型', id: '2',
  58. children: [
  59. {
  60. name: '港珠澳大桥2',
  61. children: [
  62. { name: '港珠澳大桥', detail: '这个项目非常好……' },
  63. { name: '港珠澳大桥', detail: '这个项目非常好……' },
  64. { name: '港珠澳大桥', detail: '这个项目非常好……' },
  65. ]
  66. },
  67. ]
  68. },
  69. ],
  70. cateList: [],
  71. // 二级分类的列表
  72. cateLevel2: [],
  73. checkId: "1"
  74. }
  75. },
  76. methods: {
  77. choose(id) {
  78. this.checkId = id
  79. this.typeList.forEach(item => {
  80. if (item.id == id) {
  81. this.cateLevel2 = item.children
  82. }
  83. });
  84. this.scrollTop = this.scrollTop === 0 ? 1 : 0
  85. console.log(this.cateLevel2);
  86. },
  87. getCateList() {
  88. this.cateLevel2 = this.typeList[0].children
  89. console.log(this.cateLevel2);
  90. }
  91. },
  92. onLoad() {
  93. const sysInfo = uni.getSystemInfoSync()
  94. this.wh = sysInfo.windowHeight - 50
  95. this.getCateList()
  96. },
  97. }
  98. </script>
  99. <style lang="less" scoped>
  100. .containar {
  101. .typeAndList {
  102. display: flex;
  103. justify-content: space-between;
  104. .type {
  105. width: 158rpx;
  106. background: #f8f8f8;
  107. border-radius: 0 25rpx 0 0;
  108. .typeItem {
  109. width: 100%;
  110. height: 152rpx;
  111. display: flex;
  112. justify-content: space-between;
  113. align-items: center;
  114. color: #9a9a9a;
  115. .active {
  116. width: 8rpx;
  117. height: 48rpx;
  118. background: #294994;
  119. }
  120. .item {
  121. width: 130rpx;
  122. padding: 0 10rpx;
  123. text-align: left;
  124. height: 48rpx;
  125. line-height: 48rpx;
  126. font-size: 24rpx;
  127. }
  128. }
  129. .checked {
  130. background: #ffffff;
  131. color: #302e27 !important;
  132. }
  133. }
  134. .list {
  135. width: 544rpx;
  136. padding: 0 24rpx;
  137. .typeItemBox {
  138. .typeName {
  139. padding: 18rpx 0;
  140. color: #2d2e2e;
  141. font-size: 24rpx;
  142. position: sticky;
  143. top: 0;
  144. background: #ffffff;
  145. }
  146. .boxList {
  147. .box {
  148. width: 100%;
  149. display: flex;
  150. justify-content: start;
  151. margin-bottom: 18rpx;
  152. img {
  153. width: 162rpx;
  154. height: 162rpx;
  155. border-radius: 25rpx;
  156. }
  157. .contBox {
  158. width: 406rpx;
  159. padding-left: 22rpx;
  160. .title {
  161. width: 100%;
  162. overflow: hidden;
  163. font-weight: 700;
  164. font-size: 24rpx;
  165. margin-bottom: 8rpx;
  166. }
  167. .intro {
  168. color: #a9b7c8;
  169. font-size: 22rpx;
  170. height: 80rpx;
  171. overflow: hidden;
  172. }
  173. .btnBox {
  174. display: flex;
  175. justify-content: flex-end;
  176. .btn {
  177. height: 36rpx;
  178. padding: 0 10rpx;
  179. text-align: center;
  180. line-height: 36rpx;
  181. font-size: 24rpx;
  182. border-radius: 25rpx;
  183. background: #294994;
  184. color: #fff;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/698522
推荐阅读
相关标签
  

闽ICP备14008679号