当前位置:   article > 正文

uniapp 学习笔记十六 底部菜单结构自定义搭建_uniapp底部子菜单

uniapp底部子菜单

uniapp 学习笔记十六 底部菜单结构自定义搭建

底部菜单触发不同分类数据渲染

分类遮罩交互渲染

 

cake.vue

  1. <template>
  2. <view>
  3. <nav-custom></nav-custom>
  4. <view class="cont">
  5. <good-item v-for="(item,index) in glist" :gdata="item"></good-item>
  6. </view>
  7. <view class="fixed flex justify-center bg-fff padding-sm">
  8. <view v-for="(item,index) in tabArr" :key="index" @tap="handleTab(item)"
  9. class="flex justify-around align-center">
  10. <view class="">{{item.name}}</view>
  11. <u-line v-if="index<tabArr.length-1" direction="col" length="15" margin="30upx"></u-line>
  12. </view>
  13. </view>
  14. <u-popup :show="show" mode="left" @close="handleClose">
  15. <view class="pop-cont">
  16. <view v-for="(item,index) in cfylist" class="padding-sm u-border-bottom">
  17. {{item.bname}}
  18. <view v-if="index==0">
  19. <view @tap="listShow=!listShow" class="padding-tb-sm u-border-top margin-top">
  20. 口味筛选
  21. </view>
  22. <u-cell-group v-if="listShow">
  23. <u-cell v-for="(itm,idx) in item.list" :title="itm.tname" isLink></u-cell>
  24. </u-cell-group>
  25. <view @tap="sceneShow=!sceneShow" class="padding-tb-sm u-border-top">
  26. 场景筛选
  27. </view>
  28. <u-cell-group v-if="sceneShow">
  29. <u-cell v-for="(itm,idx) in item.scene" :title="itm.tname" isLink></u-cell>
  30. </u-cell-group>
  31. </view>
  32. </view>
  33. </view>
  34. </u-popup>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. cfylist:[],
  42. sceneShow:false,
  43. listShow:false,
  44. show: false,
  45. glist: [],
  46. page: 0,
  47. tabArr: [{
  48. name: '分类',
  49. bcid: '',
  50. target: ''
  51. },
  52. {
  53. name: '蛋糕',
  54. bcid: '1',
  55. target: '/pages/cake'
  56. },
  57. {
  58. name: '面包',
  59. bcid: '11',
  60. target: '/pages/bread'
  61. },
  62. {
  63. name: '小食',
  64. bcid: '6',
  65. target: '/pages/food'
  66. },
  67. {
  68. name: '购物车',
  69. bcid: '',
  70. target: '/pages/cart'
  71. }
  72. ]
  73. }
  74. },
  75. computed:{
  76. num(){
  77. return this.$store.state.num
  78. }
  79. },
  80. methods: {
  81. handleDetail(idx) {
  82. console.log(idx);
  83. uni.navigateTo({
  84. url: '../detail/detail?idx=' + idx
  85. })
  86. },
  87. loadData(bcid = 1) {
  88. let skip = this.page * 8
  89. let url = `/1.1/classes/goods?where={"bcid":${bcid}}&limit=8&skip=${skip}`;
  90. this.$get(url).then(res => {
  91. uni.stopPullDownRefresh()
  92. let {
  93. results
  94. } = res
  95. if (results.length) {
  96. this.page++
  97. this.glist = [
  98. ...this.glist,
  99. ...res.results
  100. ]
  101. return
  102. }
  103. uni.showToast({
  104. title: '这回真没了...',
  105. icon: 'none'
  106. })
  107. })
  108. },
  109. handleTab(item) {
  110. let {
  111. bcid,
  112. target
  113. } = item
  114. if (bcid) {
  115. this.glist = []
  116. this.page = 0
  117. this.loadData(bcid)
  118. }
  119. if (!bcid && !target) {
  120. this.show = true
  121. }
  122. },
  123. handleClose(){
  124. this.show = false
  125. }
  126. },
  127. onLoad() {
  128. this.loadData()
  129. this.$get('/1.1/classes/classify').then(res=>{
  130. console.log(res)
  131. this.cfylist = res.results
  132. })
  133. },
  134. onReachBottom() {
  135. console.log('触底了');
  136. this.loadData()
  137. },
  138. onPullDownRefresh() {
  139. this.glist = []
  140. this.page = 0
  141. this.loadData()
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. page {
  147. padding-top: 100upx;
  148. padding-bottom: 120upx;
  149. }
  150. .cont {
  151. display: flex;
  152. flex-wrap: wrap;
  153. padding: 15upx;
  154. justify-content: space-between;
  155. }
  156. .fixed {
  157. position: fixed;
  158. bottom: 0;
  159. left: 0;
  160. width: 100%;
  161. box-shadow: 0 0 10upx 2upx rgba(0, 0, 0, 0.2);
  162. }
  163. .cu-bar{
  164. position: fixed;
  165. top: 0;
  166. left: 0;
  167. width: 100%;
  168. z-index: 2;
  169. }
  170. .pop-cont{
  171. width: 400upx;
  172. margin-top: 200upx;
  173. }
  174. </style>

page.json

  1. {
  2. "path" : "pages/cake/cake",
  3. "style" :
  4. {
  5. "navigationBarTitleText": "",
  6. "enablePullDownRefresh": true,
  7. "navigationStyle": "custom"
  8. }
  9. },

nav-custom.vue

  1. <template>
  2. <view class="cu-bar bg-white">
  3. <view class="action">
  4. <text class="cuIcon-locationfill text-gray"></text>
  5. 重庆
  6. </view>
  7. <view class="content text-bold">
  8. Macoffee
  9. </view>
  10. <view class="action text-gray">
  11. <text class="cuIcon-search"></text>
  12. <u-line direction="col" length="15" margin="20upx"></u-line>
  13. <text class="cuIcon-sort"></text>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name:"nav-custom",
  20. data() {
  21. return {
  22. };
  23. }
  24. }
  25. </script>
  26. <style lang="scss">
  27. .cu-bar{
  28. position: fixed;
  29. top: 0;
  30. left: 0;
  31. width: 100%;
  32. z-index: 2;
  33. }
  34. </style>

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

闽ICP备14008679号