当前位置: 首页 > news >正文

网站建站在线制作山东网建设

网站建站在线制作,山东网建设,高端营销型网站建设品牌,做网站需要写代码吗原博:https://juejin.cn/post/7365533404790341651 在开发微信小程序,通常会使用uniapp自带的tabBar实现底部图标和导航,但现实有少量应用使用uniapp自带的tabBar无法满足需求,这时需要自定义底部tabBar功能。 例如下图的需求&am…

原博:https://juejin.cn/post/7365533404790341651

在开发微信小程序,通常会使用uniapp自带的tabBar实现底部图标和导航,但现实有少量应用使用uniapp自带的tabBar无法满足需求,这时需要自定义底部tabBar功能。 例如下图的需求,在中间添加一个加号,例如根据不同登录的角色显示不同的tabBar按钮等,这些功能在无法通过 uniapp自带的tabBar实现所以需要写相关组件逻辑。

image.png

常规tabBar

常规实现底部导航的效果,可以参考官方文档 uniapp添加tabBar官方文档地址: uniapp.dcloud.net.cn/collocation…

下面将下图为示例写部分代码案例: 在pages.json写上tabBar 并在List定义好每个页面与页面展示图标,以及不同选中时图标的效果,就可以实现下面页面展示的样式:

image.png

 案例代码: 注意导航页的图标和页面都必须在根路径下面,因此不能使用网络地址,或分包下的图片和页面。

 "tabBar": {"color": "#bababa","selectedColor": "#000000","borderStyle": "black","backgroundColor": "#ffffff","list": [{"pagePath": "pages/tabbar/index/index","iconPath": "static/images/common/shouye.png","selectedIconPath": "static/images/common/shouye-xz.png","text": "首页"},{"pagePath": "pages/talent/index","iconPath": "static/images/common/task.png","selectedIconPath": "static/images/common/task_d.png","text": "达人任务"},{"pagePath": "pages/tabbar/facilitator/facilitator","iconPath": "static/images/common/facilitator.png","selectedIconPath": "static/images/common/facilitator_d.png","text": "服务商"},{"pagePath": "pages/aiTools/aiTools","iconPath": "static/images/common/aitools.png","selectedIconPath": "static/images/common/aitools_d.png","text": "创作助手"},{"pagePath": "pages/tabbar/info/info","iconPath": "static/images/common/info.png","selectedIconPath": "static/images/common/info_d.png","text": "我的"}]},

自定义tabBar

梳理业务:

  1. 去除pages.json写上tabBar注释相关代码;
  2. 通过uni.hideTabBar();隐藏uniapp自带的tabBar;
  3. 自定义tabBar组件,实现页面相关逻辑;
  4. 在相关页面引入该组件;
  5. 根据在页面的onShow方法,当页面显示通过$ref,调用相关逻辑,判断需要显示的底部tabBar按钮和样式。

下面将以下图为案例写相关逻辑:

image.png

  1. 去除pages.json写上tabBar注释相关代码,图上写了一个list.pagePath 主要的作用是占位,没别的意义

image.png

2.封装tabBar.vue组件

ps:我在components\tabbar\tabbar.vue路径下封装tabBar.vue组件,其他的小伙伴可以根据自己的页面需求写在对应位置,例如想实现首页点击进入不同的分包和页面展示不同的tabBar,那么可以根据自己的需求进行调整。

 

<template><view class="tabbar"><view class="tabbar-item" v-for="(item, index) in list" :key="index" @click="changeTab(index)"><template v-if="index != 2"><view class="select" v-if="current == index"><view><view class="i-t position"><image class="img imgactive" mode="widthFix" :src="item.selectedIconPath"v-if="current == index"></image><image class="img" mode="widthFix" :src="item.iconPath" v-else></image><view class="text active" v-if="current == index">{{ item.text }}</view><view class="text" v-else>{{ item.text }}</view></view></view></view><view v-else><view class="i-t"><image class="img" mode="widthFix" :src="item.selectedIconPath" v-if="current == index"></image><image class="img" mode="widthFix" :src="item.iconPath" v-else></image><view class="text active" v-if="current == index">{{ item.text }}</view><view class="text" v-else>{{ item.text }}</view></view></view></template><!-- 下面是为了解决自定义业务需求,如果is_identity = 3则显示中间的加号,不然显示服务商 --><template v-else><view class="i-t" v-if="is_identity == 3" ><image class="img" mode="widthFix" :src="urladdTask" style="width: 140rpx;height: 140rpx;position: absolute;top: -50rpx;"></image></view><view class="i-t" v-else><view class="select" v-if="current == index"><view><view class="i-t position"><image class="img imgactive" mode="widthFix" :src="item.selectedIconPath"v-if="current == index"></image><image class="img" mode="widthFix" :src="item.iconPath" v-else></image><view class="text active" v-if="current == index">{{ item.text }}</view><view class="text" v-else>{{ item.text }}</view></view></view></view><view v-else><view class="i-t"><image class="img" mode="widthFix" :src="item.selectedIconPath" v-if="current == index"></image><image class="img" mode="widthFix" :src="item.iconPath" v-else></image><view class="text active" v-if="current == index">{{ item.text }}</view><view class="text" v-else>{{ item.text }}</view></view></view></view></template></view></view>
</template><script>
//引入图片资源
import addTask from '../../static/images/common/addTask.png'
export default {name: "tabbar",props: ['current'],data() {return {urladdTask: addTask,is_identity: 0,// TODO: 下面list则是你页面上具体展示的底部按钮,根据你的需求和页面进行调整list: [{"pagePath": "pages/tabbar/index/index","iconPath": "../../static/images/common/shouye.png","selectedIconPath": "../../static/images/common/shouye-xz.png","text": "首页"},{"pagePath": "pages/talent/index","iconPath": "../../static/images/common/task.png","selectedIconPath": "../../static/images/common/task_d.png","text": "达人任务"},{"pagePath": "pages/tabbar/facilitator/facilitator","iconPath": "../../static/images/common/facilitator.png","selectedIconPath": "../../static/images/common/facilitator_d.png","text": "服务商"},{"pagePath": "pages/aiTools/aiTools","iconPath": "../../static/images/common/aitools.png","selectedIconPath": "../../static/images/common/aitools_d.png","text": "创作助手"},{"pagePath": "pages/tabbar/info/info","iconPath": "../../static/images/common/info.png","selectedIconPath": "../../static/images/common/info_d.png","text": "我的"}]}},created() {//隐藏tabbaruni.hideTabBar();},mounted() {},methods: {changeTab(e) {uni.switchTab({url: '/' + this.list[e].pagePath,})}}}</script><style>
.tabbar {font-size: 1.5vh;position: fixed;left: 0;bottom: 0;z-index: 99;width: 100%;height: 6vh;display: grid;grid-template-columns: repeat(5, 1fr);align-items: center;justify-content: space-around;background-color: #fff;padding: 20rpx 0;
}.tabbar-item {height: 100%;display: flex;align-items: center;justify-content: center;position: relative;
}
.img {height: 3vh;width: 2.5vh;
}
.text {text-align: center;color: #CACACA;
}
.i-t {display: flex;flex-direction: column;justify-items: center;align-items: center;
}
.select {position: relative;
}.text.active {color: red;
}
.index0 {width: 80rpx;height: 80rpx;
}
</style>
  1. 组件封装完毕需要在对应的页面中引入该组件 例如 下面index.vue
  2. </template></view>//current则表示选中的状态,例如当前是首页则current为0,如果是第三页则current=2<tabbar current="0" ref="mytabbar"></tabbar></view>
    </template><script>import tabbar from '@/components/tabbar/tabbar.vue';
    export default {components: {tabbar},
    }
    

  3. 在tabBar.vue组件写上相关页面判断,例如不同的角色则显示不同的按钮,或不同样式。 tabBar.vue组件中的methods添加一个init函数:
  4.     init() {//获取用户信息let userinfo = uni.getStorageSync('user');// 获取角色状态,赋值给is_identityif (userinfo) {this.is_identity = userinfo?.identity;}//...其他调接口等业务处理}
    

    在第三步的index.vue页面中,引入的tabbar组件定义了一个ref="mytabbar",可以通过this.$refs.tabBar.init();的方式来调用tabBar.vue组件中的methods的init函数。 例如在index.vue组件下的onShow方法下,当页面显示时候执行tabBar.vue组件中的methods的init函数

        async onShow() {await this.getuserinfo();//其他业务},
    

http://www.yayakq.cn/news/115310/

相关文章:

  • 宁波市建设工程检测协会网站网站建设项目总结
  • 美橙网站建设经典案例整合营销传播名词解释
  • 电子商务网站建设实训个人总结毕业作品是做网站的答辩会问什么
  • 宁波网站建设的过程wordpress 置顶
  • 秦皇岛网站建设兼职公益建设网站的作用
  • 图书馆网站建设调查问卷设计制作实践活动100字
  • 修改网站模板网站建设哈尔滨app开发2
  • 视频网站的服务器建设做pc端网站价位
  • 国外做ae模板网站大全网页制作培训班前景
  • 网站掉排名崇文企业网站建设公司
  • 梅林做网站深圳网络推广顾问
  • 宝思哲手表网站谁有免费网址发给我谢谢
  • 中山模板建站软件学校网站建设分析
  • php 手机网站 上传图片短链接在线工具
  • 手机网站商城建设那个网站做拍手比较好
  • 分享网站模板网站流量 龙优化软件
  • 哪些有名网站是用php做的wordpress禁止右键弹出菜单
  • 青浦建设网站公司网站建设和网站设计
  • wordpress多语言建站收款 wordpress
  • flash 的网站去哪里找空间做网站
  • 江西省城乡住房建设厅网站网站单页面制作
  • linux 做网站用哪个版本微信小程序开发一个多少钱啊
  • 高端网站源码小说阅读网站建设市场需求分析
  • 网站建设需要的语言改号宝网站搭建
  • 做网站比较好网站批量修改
  • 手表网站app天河网站 建设信科网络
  • 外贸网站建设不可缺少的灵活性网站建设中如何兼容所有浏览器
  • html网站开发流程网站怎么做微信接口
  • 东莞做公众号的网站网站开发项目团队人员
  • 怎么建设分销模式手机网站做网站gzip压缩