Tabs: update on resize, fixed (#3890) (#3938)

* Tabs: update on resize, fixed #3890

* Tabs: update on resize, fixed #3890
pull/4047/head
pengchongfu 2017-04-06 18:55:59 +08:00 committed by baiyaaaaa
parent cc1349eba9
commit 640054bd1c
1 changed files with 30 additions and 16 deletions

View File

@ -1,5 +1,6 @@
<script> <script>
import TabBar from './tab-bar'; import TabBar from './tab-bar';
import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
function noop() {} function noop() {}
@ -90,10 +91,8 @@
}, },
setOffset(value) { setOffset(value) {
this.navStyle.transform = `translateX(-${value}px)`; this.navStyle.transform = `translateX(-${value}px)`;
}
}, },
update() {
updated() {
const navWidth = this.$refs.nav.offsetWidth; const navWidth = this.$refs.nav.offsetWidth;
const containerWidth = this.$refs.navScroll.offsetWidth; const containerWidth = this.$refs.navScroll.offsetWidth;
const currentOffset = this.getCurrentScrollOffset(); const currentOffset = this.getCurrentScrollOffset();
@ -106,10 +105,17 @@
if (navWidth - currentOffset < containerWidth) { if (navWidth - currentOffset < containerWidth) {
this.setOffset(navWidth - containerWidth); this.setOffset(navWidth - containerWidth);
} }
} else if (currentOffset > 0) { } else {
this.scrollable = false; this.scrollable = false;
if (currentOffset > 0) {
this.setOffset(0); this.setOffset(0);
} }
}
}
},
updated() {
this.update();
}, },
render(h) { render(h) {
@ -170,6 +176,14 @@
</div> </div>
</div> </div>
); );
},
mounted() {
addResizeListener(this.$el, this.update);
},
beforeDestroy() {
if (this.$el && this.update) removeResizeListener(this.$el, this.update);
} }
}; };
</script> </script>