mirror of https://github.com/ElemeFE/element
* Tabs: update on resize, fixed #3890 * Tabs: update on resize, fixed #3890pull/4047/head
parent
cc1349eba9
commit
640054bd1c
|
@ -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,26 +91,31 @@
|
||||||
},
|
},
|
||||||
setOffset(value) {
|
setOffset(value) {
|
||||||
this.navStyle.transform = `translateX(-${value}px)`;
|
this.navStyle.transform = `translateX(-${value}px)`;
|
||||||
|
},
|
||||||
|
update() {
|
||||||
|
const navWidth = this.$refs.nav.offsetWidth;
|
||||||
|
const containerWidth = this.$refs.navScroll.offsetWidth;
|
||||||
|
const currentOffset = this.getCurrentScrollOffset();
|
||||||
|
|
||||||
|
if (containerWidth < navWidth) {
|
||||||
|
const currentOffset = this.getCurrentScrollOffset();
|
||||||
|
this.scrollable = this.scrollable || {};
|
||||||
|
this.scrollable.prev = currentOffset;
|
||||||
|
this.scrollable.next = currentOffset + containerWidth < navWidth;
|
||||||
|
if (navWidth - currentOffset < containerWidth) {
|
||||||
|
this.setOffset(navWidth - containerWidth);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.scrollable = false;
|
||||||
|
if (currentOffset > 0) {
|
||||||
|
this.setOffset(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updated() {
|
updated() {
|
||||||
const navWidth = this.$refs.nav.offsetWidth;
|
this.update();
|
||||||
const containerWidth = this.$refs.navScroll.offsetWidth;
|
|
||||||
const currentOffset = this.getCurrentScrollOffset();
|
|
||||||
|
|
||||||
if (containerWidth < navWidth) {
|
|
||||||
const currentOffset = this.getCurrentScrollOffset();
|
|
||||||
this.scrollable = this.scrollable || {};
|
|
||||||
this.scrollable.prev = currentOffset;
|
|
||||||
this.scrollable.next = currentOffset + containerWidth < navWidth;
|
|
||||||
if (navWidth - currentOffset < containerWidth) {
|
|
||||||
this.setOffset(navWidth - containerWidth);
|
|
||||||
}
|
|
||||||
} else if (currentOffset > 0) {
|
|
||||||
this.scrollable = false;
|
|
||||||
this.setOffset(0);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
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>
|
||||||
|
|
Loading…
Reference in New Issue