From 32af1d327e810ab0dc489ab35cd71069ae9057b5 Mon Sep 17 00:00:00 2001 From: zhenyulei Date: Sun, 27 Sep 2020 17:38:30 +0800 Subject: [PATCH] feat: update tabbar --- src/packages/tabbar/doc.md | 3 ++- src/packages/tabbar/tabbar.vue | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/packages/tabbar/doc.md b/src/packages/tabbar/doc.md index 46b4267a4..ea9294cb5 100644 --- a/src/packages/tabbar/doc.md +++ b/src/packages/tabbar/doc.md @@ -68,7 +68,7 @@ export default { **重要提示** -组件中的 curr 属性相当于默认的选中tab,如果tabbar组件被应用于跳转路由,若tabbar没有按照预想的选中高亮的话,请注意,一般是因为重新渲染了tabbar组件导致的,解决方法如下: +组件中的 curr 属性相当于默认的选中tab,如果tabbar组件被应用于跳转路由,设置 isRouter = true ,若tabbar没有按照预想的选中高亮的话,请注意,一般是因为重新渲染了tabbar组件导致的,解决方法如下: - 方法1、通过监听切换事件 @tab-switch 改变传入数据 tabList 中想要高亮对象的 curr 值为 true; - 方法2、把 tabbar 组件放在路由层级之外,令其独立出来,避免点击 tabbar 会重新渲染该组件; @@ -83,6 +83,7 @@ export default { | tabbar-list | 渲染数据 | Array | [] | bottom | 是否固定在页面底部 |Boolean|false| | replace | replace为true的时候,跳转url以替换的形式进行 |Boolean|false| +| isRouter | 是否为vue路由跳转形式,区别于H5的web跳转|Boolean|false| ### tabbar-list diff --git a/src/packages/tabbar/tabbar.vue b/src/packages/tabbar/tabbar.vue index 88e666456..21468804a 100644 --- a/src/packages/tabbar/tabbar.vue +++ b/src/packages/tabbar/tabbar.vue @@ -40,6 +40,10 @@ export default { type: Boolean, default: false, }, + isRouter: { + type: Boolean, + default: false, + }, }, data() { return { @@ -71,10 +75,10 @@ export default { this.currIndex = index; if (this.replace) { //替换url - window.location.replace(value.href); + this.isRouter ? this.$router.replace(value.href) : window.location.replace(value.href); } else { if (value.href) { - window.location.href = value.href; + this.isRouter ? this.$router.push(value.href) : (window.location.href = value.href); } } this.$emit('tab-switch', value, index); -- GitLab