uni-app 导航栏标签页切换

 

uni-app 导航栏标签页切换

<template>
 <view>
  <view class="tab_nav">
   <view class="navTitle" v-for="(item,index) in navList" :key="index" >
    <view :class="{'active':isActive === index}" @click="checked(index)">
     {{item.title}}
    </view>
   </view>
  </view>
  <view class="nav_item" v-if="isActive==0">0</view>
  <view class="nav_item" v-if="isActive==1">1</view>
  <view class="nav_item" v-if="isActive==2">2</view>
 </view>
</template>

<script>
 export default {
   data() {
    return {
     isActive: 0,
     navList:[
      {
       index: 0,
       title: '标题一'
      },{
       index: 1,
       title: "标题二"
      },{
       index: 2,
       title: "标题三"
      }
     ]
    }
   },
   methods: {
    checked(index) {
     this.isActive = index
    },
   }
  }
</script>

<style>
 .tab_nav{
  display: flex;
  justify-content: center;
  align-items: center;
 }
 .tab_nav  .navTitle {
  height: 90rpx;
  line-height: 90rpx;
  width: 100%;
  text-align: center;
  font-size: 32rpx;
  font-family: Alibaba PuHuiTi;
  color: #333;
 }
 .active {
  position: relative;
  color: #333;
 }
 .active::after {
  content: "";
  position: absolute;
  width: 100rpx;
  height: 8rpx;
  background-color:  #FFC125;
  left: 0px;
  right: 0px;
  bottom: 0px;
  margin: auto;
 }
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp中设置标签可以通过使用面框架底部的tabBar来实现。具体步骤如下: 1.在pages.json文件中添加tabBar选项,并设置相应的跳转路径和图标,例如: "tabBar": { "color": "#999", "selectedColor": "#007aff", "backgroundColor": "#fff", "list": [ { "pagePath": "pages/index/index", "text": "首", "iconPath": "static/tabbar/home.png", "selectedIconPath": "static/tabbar/home-active.png" }, { "pagePath": "pages/list/list", "text": "列表", "iconPath": "static/tabbar/list.png", "selectedIconPath": "static/tabbar/list-active.png" }, { "pagePath": "pages/my/my", "text": "我的", "iconPath": "static/tabbar/my.png", "selectedIconPath": "static/tabbar/my-active.png" } ] } 2.在每个对应的面中使用自定义组件来展示标签栏,例如: <template> <view class="index"> <view>这是首</view> <tabbar></tabbar> </view> </template> <script> import tabbar from '@/components/tabbar/index.vue' export default { name: 'index', components: { tabbar } } </script> 3.完善自定义组件的功能和样式,例如: <template> <view class="tabbar"> <view class="item" v-for="(item, index) in list" :key="index" @click="redirectTo(item)"> <image :src="item.selected ? item.selectedIconPath : item.iconPath"></image> <text :class="item.selected ? 'active' : ''">{{ item.text }}</text> </view> </view> </template> <script> export default { name: 'tabbar', props: { list: { type: Array, default: () => [] } }, methods: { redirectTo (item) { if (item.pagePath !== this.$mp.page.route) { uni.redirectTo({ url: '/' + item.pagePath }) } } } } </script> <style> .tabbar { display: flex; justify-content: space-between; position: fixed; bottom: 0; height: 60rpx; width: 100%; background-color: #fff; box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.2); } .item { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; width: 33.33%; font-size: 26rpx; color: #999; transition: color 0.3s ease-in-out; } .item.active { color: #007aff; } .item image { height: 40rpx; width: 40rpx; margin-bottom: 6rpx; } </style> 通过以上操作,一个简单的uniapp标签就可以实现了。需要注意的是,tabBar组件在uniapp中只能在底部展示,且只能同时展示5个标签
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值