tabbar的一个小bug

41 阅读1分钟

进入消息页后返回到订单页会不高亮

image.png

原因:进入消息页因为下面语句销毁tabbar <TabBar v-if="!route.meta.hideTabBar" />

所以再回去后会重新创建watch监听可能来不及执行监听操作

watch(route,(newRoute) => {
  const index = tabbarData.findIndex(item => item.path === newRoute.path)
  if (index=== -1 ) return 
  currentIndex.value = index
})

解决办法,不使用v-if,改为v-show,这样可保证一直在监听