|
|
@@ -95,21 +95,20 @@ export default {
|
|
95
|
95
|
return activePath;
|
|
96
|
96
|
},
|
|
97
|
97
|
},
|
|
|
98
|
+ beforeMount() {
|
|
|
99
|
+ window.addEventListener('resize', this.setVisibleNumber)
|
|
|
100
|
+ },
|
|
|
101
|
+ beforeDestroy() {
|
|
|
102
|
+ window.removeEventListener('resize', this.setVisibleNumber)
|
|
|
103
|
+ },
|
|
98
|
104
|
mounted() {
|
|
99
|
105
|
this.setVisibleNumber();
|
|
100
|
106
|
},
|
|
101
|
107
|
methods: {
|
|
102
|
108
|
// 根据宽度计算设置显示栏数
|
|
103
|
109
|
setVisibleNumber() {
|
|
104
|
|
- const width = document.body.getBoundingClientRect().width - 380;
|
|
105
|
|
- const elWidth = this.$el.getBoundingClientRect().width;
|
|
106
|
|
- const menuItemNodes = this.$el.children;
|
|
107
|
|
- const menuWidth = Array.from(menuItemNodes).map(
|
|
108
|
|
- (i) => i.getBoundingClientRect().width
|
|
109
|
|
- );
|
|
110
|
|
- this.visibleNumber = (
|
|
111
|
|
- parseInt(width - elWidth) / parseInt(menuWidth)
|
|
112
|
|
- ).toFixed(0);
|
|
|
110
|
+ const width = document.body.getBoundingClientRect().width / 3;
|
|
|
111
|
+ this.visibleNumber = parseInt(width / 85);
|
|
113
|
112
|
},
|
|
114
|
113
|
// 菜单选择事件
|
|
115
|
114
|
handleSelect(key, keyPath) {
|