当前位置:   article > 正文

uniapp 学习笔记三十五 首页底部菜单独立封装_uniapp 做一个圆弧形菜单

uniapp 做一个圆弧形菜单

uniapp 学习笔记三十五 首页底部菜单独立封装

homee.vue

  1. <template>
  2. <scroll-view class="scroll-cont" :scroll-into-view="topItem" @scroll="handleScroll" scroll-y="true" scroll-with-animation="true">
  3. <view>
  4. <view id="top"></view>
  5. <!-- 自定义导航栏 -->
  6. <nav-custom></nav-custom>
  7. <!-- 轮播 -->
  8. <swiper class="banner" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
  9. <swiper-item v-for="(item,index) in banner" :key="item.objectId">
  10. <image :src="item.img" @tap="handleBanner(item.link)"></image>
  11. </swiper-item>
  12. </swiper>
  13. <home-title
  14. title="本季推荐"
  15. en-title="Seasonal Recommend"
  16. en-tit="Seasonal"
  17. ></home-title>
  18. <scroll-view scroll-x="true" >
  19. <view class="scroll-inner">
  20. <image src="../../static/logo.png" mode="heightFix"></image>
  21. <image src="../../static/logo1.png" mode="heightFix"></image>
  22. <image src="../../static/logo.png" mode="heightFix"></image>
  23. <image src="../../static/logo1.png" mode="heightFix"></image>
  24. </view>
  25. </scroll-view>
  26. <home-title
  27. title="法式经典"
  28. en-title="French Classic"
  29. en-tit="French"
  30. ></home-title>
  31. <image class="classify" src="../../static/logo.png" mode=""></image>
  32. <view class="flex flex-wrap padding-sm justify-between">
  33. <good-item v-for="(item,index) in 4"></good-item>
  34. </view>
  35. <view class="back-top" v-if="isShowGoTop" @tap="handleBackTop">
  36. <text class="iconfont icon-huidingbu"></text>
  37. </view>
  38. </view>
  39. <tab-custom></tab-custom>
  40. </scroll-view>
  41. </template>
  42. <script>
  43. // 局部引入封装的 promise $http
  44. import {$http} from '@/utils/request.js'
  45. export default {
  46. data() {
  47. return {
  48. isShowGoTop:false,
  49. topItem:'', //返回顶部的标记点
  50. banner:[]
  51. }
  52. },
  53. methods: {
  54. handleScroll(ev){
  55. // console.log(ev.detail);
  56. let {scrollTop} = ev.detail
  57. this.isShowGoTop = scrollTop >600
  58. this.topItem = '' //重置定位返回点
  59. },
  60. handleBackTop(){
  61. this.topItem = 'top'
  62. },
  63. handleBanner(link){
  64. uni.navigateTo({
  65. url:`banner-ad?link=${link}`
  66. })
  67. }
  68. },
  69. onLoad() {
  70. // 方法三 使用全局封装的 $get方法
  71. this.$get('/1.1/classes/banner').then(res=>{
  72. this.banner = res.results //取回数据并指定到swiper
  73. })
  74. }
  75. }
  76. </script>
  77. <style lang="scss">
  78. .back-top{
  79. height: 100upx;
  80. width: 100upx;
  81. background-color: #fff;
  82. border-radius: 50%;
  83. box-shadow: 0 0 10upx 4upx rgba(0, 0, 0, 0.4);
  84. position: fixed;
  85. bottom: 40upx;
  86. right: 20upx;
  87. text-align: center;
  88. line-height: 100upx;
  89. }
  90. .classify{
  91. height: 380upx;
  92. width: 100%;
  93. }
  94. .scroll-inner{
  95. white-space: nowrap;
  96. image{
  97. height: 290upx;
  98. width: auto;
  99. }
  100. }
  101. .banner{
  102. height: 1000upx;
  103. swiper-item{
  104. height: 1000upx;
  105. }
  106. image{
  107. width: 100%;
  108. height:1000upx
  109. }
  110. }
  111. .scroll-cont{
  112. height: 100vh;
  113. }
  114. </style>

main.js

  1. import App from './App'
  2. import store from 'store/index.js' //引入自定义的store
  3. // #ifndef VUE3
  4. import Vue from 'vue'
  5. Vue.config.productionTip = false
  6. App.mpType = 'app'
  7. const app = new Vue({
  8. ...App,
  9. store //注入状态机
  10. })
  11. // 全局引入uView主JS库
  12. import uView from '@/uni_modules/uview-ui'
  13. Vue.use(uView)
  14. // 全局引入自定义组件
  15. import NavCustom from '@/components/nav-custom.vue'
  16. Vue.component('nav-custom',NavCustom)
  17. import HomeTitle from '@/components/home-title.vue'
  18. Vue.component('home-title',HomeTitle)
  19. import GoodItem from '@/components/goods-item.vue'
  20. Vue.component('good-item',GoodItem)
  21. import TabCustom from '@/components/tab-custom.vue'
  22. Vue.component('tab-custom',TabCustom)
  23. // 挂载全局异步请求方法(单个挂载)
  24. /* import {$http,$get,$post,$put} from '@/utils/request.js'
  25. Vue.prototype.$http = $http
  26. Vue.prototype.$get = $get
  27. Vue.prototype.$post = $post
  28. Vue.prototype.$put = $put */
  29. // 挂载全局异步请求方法(批量挂载request.js里面的所有方法)
  30. import * as request from '@/utils/request.js'
  31. for (let key in request) {
  32. Vue.prototype[key] = request[key]
  33. }
  34. app.$mount()
  35. // #endif
  36. // #ifdef VUE3
  37. import { createSSRApp } from 'vue'
  38. import { from } from 'form-data'
  39. export function createApp() {
  40. const app = createSSRApp(App)
  41. return {
  42. app
  43. }
  44. }
  45. // #endif

tab-custom.vue

  1. <template>
  2. <view>
  3. <view class="fixed flex justify-center bg-fff padding-sm">
  4. <view v-for="(item,index) in tabArr" :key="index" @tap="handleTab(item)"
  5. class="flex justify-around align-center">
  6. <view class="">{{item.name}}</view>
  7. <u-line v-if="index<tabArr.length-1" direction="col" length="15" margin="30upx"></u-line>
  8. </view>
  9. </view>
  10. <u-popup :show="show" mode="left" @close="handleClose">
  11. <view class="pop-cont">
  12. <view v-for="(item,index) in cfylist">
  13. <view @click="handleList(item,0)" class="padding-sm u-border-bottom">
  14. {{item.bname}}
  15. <view class="cu-tag round bg-yellow color-fff margin-sm">
  16. {{item.num}}
  17. </view>
  18. </view>
  19. <view v-if="index==0">
  20. <view
  21. @tap="listShow=!listShow"
  22. :class="['padding-sm',{'u-border-bottom':!listShow}]"
  23. >
  24. 口味筛选
  25. </view>
  26. <u-cell-group v-if="listShow">
  27. <u-cell
  28. v-for="(itm,idx) in item.list"
  29. :title="itm.tname"
  30. isLink
  31. @click="handleList(itm,1)"
  32. ></u-cell>
  33. </u-cell-group>
  34. <view
  35. @tap="sceneShow=!sceneShow"
  36. :class="['padding-sm',{'u-border-bottom':!sceneShow}]">
  37. 场景筛选
  38. </view>
  39. <u-cell-group v-if="sceneShow">
  40. <u-cell
  41. v-for="(itm,idx) in item.scene"
  42. :title="itm.tname"
  43. isLink
  44. @click="handleList(itm,2)"
  45. ></u-cell>
  46. </u-cell-group>
  47. </view>
  48. </view>
  49. </view>
  50. </u-popup>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. name:"tab-custom",
  56. data() {
  57. return {
  58. tabArr: [{
  59. name: '分类',
  60. bcid: '',
  61. target: ''
  62. },
  63. {
  64. name: '蛋糕',
  65. bcid: '1',
  66. target: '/pages/cake/cake'
  67. },
  68. {
  69. name: '面包',
  70. bcid: '11',
  71. target: '/pages/cake/cake'
  72. },
  73. {
  74. name: '小食',
  75. bcid: '6',
  76. target: '/pages/cake/cake'
  77. },
  78. {
  79. name: '购物车',
  80. bcid: '',
  81. target: '/pages/cart/cart'
  82. }
  83. ],
  84. show: false,
  85. cfylist:[],
  86. listShow:false,
  87. sceneShow:false
  88. };
  89. },
  90. created() {
  91. this.$get('/1.1/classes/classify').then(res=>{
  92. console.log(res)
  93. this.cfylist = res.results
  94. })
  95. },
  96. methods: {
  97. handleTab(item) {
  98. let {
  99. bcid,
  100. target
  101. } = item
  102. if (bcid) { // 商品列表数据更新
  103. // this.glist = []
  104. // this.page = 0
  105. // this.condition.bcid = Number(bcid)
  106. this.$store.commit('changeCondition',{
  107. bcid:Number(bcid)
  108. })
  109. uni.navigateTo({
  110. url:target
  111. })
  112. }
  113. if (!bcid && !target) { // 侧边分类
  114. this.show = true
  115. }
  116. if (!bcid && target) {
  117. uni.navigateTo({
  118. url:target
  119. })
  120. }
  121. },
  122. handleClose(){
  123. this.show = false
  124. },
  125. handleList({bid,tid},type){
  126. let obj = {bcid:bid}
  127. // type === 1 ? obj.fid=tid : obj.sid=tid
  128. if(type===1){obj.fid=tid}
  129. if(type===2){obj.sid=tid}
  130. this.$store.commit('changeCondition',obj)
  131. this.show = false
  132. uni.navigateTo({
  133. url:'/pages/cake/cake'
  134. })
  135. }
  136. },
  137. }
  138. </script>
  139. <style lang="scss">
  140. .fixed {
  141. position: fixed;
  142. bottom: 0;
  143. left: 0;
  144. width: 100%;
  145. box-shadow: 0 0 10upx 2upx rgba(0, 0, 0, 0.2);
  146. }
  147. .pop-cont{
  148. width: 400upx;
  149. margin-top: 200upx;
  150. }
  151. </style>

 

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

闽ICP备14008679号