移动端tabbar刷新保持

刷新calendarIndex页面时 出现tabbar默认选中首页的现象
在这里插入图片描述
在这里插入图片描述
正确情况应该是 对应 “我的”
在这里插入图片描述
解决方法:

 mounted(){
   let CURRENTHREF = this.$route.path;
     if (CURRENTHREF.includes('/index')) {
      this.active = 0
    }else if(CURRENTHREF.includes('/calendarIndex')) {
      this.active = 1
    }
  }
  
  // includes() 方法用来判断一个数组是否包含一个指定的值,如果是返回 true,否则false。
  
   let CURRENTLY = window.location.pathname
    if (-1 !== CURRENTLY.indexOf('/index')) {
      this.active = 0
    } else if (-1 !== CURRENTLY.indexOf('/calendarIndex')) {
      this.active = 1
    }
   
   //indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。(在字符串内进行检索)
   //indexOf() 方法对大小写敏感!如果要检索的字符串值没有出现,则该方法返回 -1。

获取向前页面URL 的方法:( 完整URL:http://192.168.31.130:8085/home/signIn?openClassId=152#index)

  1. 完整URL : window.location.href // http://192.168.31.130:8085/home/signIn?openClassId=152#index
  2. 路由路径:this.$route.path // /signIn
  3. 路由路径参数 : this.$route.params
  4. 路由查询参数: this.$route.query // {openClassId: ‘152’}
  5. URL 的协议部分:window.location.protocol // http:
  6. URL 的主机部分: window.location.host //192.168.31.130:8085
  7. URL 的端口部分:window.location.port //8085
  8. URL 的路径部分(就是文件地址): window.location.pathname // /home/signIn
  9. 查询(参数)部分: window.location.search // ?openClassId=152
  10. 锚点:window.location.hash //#index 对用的内容
对于Vue 3和Vant移动端TabBar的使用,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Vue 3和Vant。你可以使用以下命令来安装它们: ```bash npm install vue@next vant ``` 2. 在你的Vue项目中,创建一个新的组件文件,例如`TabBar.vue`。 3. 在`TabBar.vue`文件中,引入Vue和Vant的相关组件和样式: ```javascript <template> <div> <van-tabbar v-model="active"> <van-tabbar-item icon="home-o" to="/"> 首页 </van-tabbar-item> <van-tabbar-item icon="search" to="/search"> 搜索 </van-tabbar-item> <van-tabbar-item icon="star-o" to="/favorites"> 收藏 </van-tabbar-item> <van-tabbar-item icon="contact" to="/profile"> 个人中心 </van-tabbar-item> </van-tabbar> </div> </template> <script> import { Tabbar, TabbarItem } from 'vant'; export default { components: { [Tabbar.name]: Tabbar, [TabbarItem.name]: TabbarItem, }, data() { return { active: '/', }; }, }; </script> <style> /* 这里可以添加自定义样式 */ </style> ``` 4. 在你的主应用组件中,例如`App.vue`,使用`TabBar`组件: ```html <template> <div id="app"> <!-- 其他内容 --> <TabBar /> </div> </template> <script> import TabBar from './components/TabBar.vue'; export default { components: { TabBar, }, }; </script> <style> /* 这里可以添加全局样式 */ </style> ``` 5. 最后,你可以根据自己的需要在`TabBar.vue`中设置每个Tab项的图标、文字和链接。你还可以通过修改`active`的值来控制当前选中的Tab。 这样,你就可以在Vue 3项目中使用Vant移动端TabBar了。记得根据自己的需求进行样式和功能的调整。希望对你有帮助!如果有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值