Skip to content

Commit 9677406

Browse files
authored
perf[TagsView]: set the scrollPane as a business component (PanJiaChen#1660)
1 parent 1e06f1d commit 9677406

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/components/ScrollPane/index.vue renamed to src/views/layout/components/TagsView/ScrollPane.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ export default {
1414
left: 0
1515
}
1616
},
17+
computed: {
18+
scrollWrapper() {
19+
return this.$refs.scrollContainer.$refs.wrap
20+
}
21+
},
1722
methods: {
1823
handleScroll(e) {
1924
const eventDelta = e.wheelDelta || -e.deltaY * 40
20-
const $scrollWrapper = this.$refs.scrollContainer.$refs.wrap
25+
const $scrollWrapper = this.scrollWrapper
2126
$scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4
2227
},
2328
moveToTarget(currentTag) {
2429
const $container = this.$refs.scrollContainer.$el
2530
const $containerWidth = $container.offsetWidth
26-
const $scrollWrapper = this.$refs.scrollContainer.$refs.wrap
31+
const $scrollWrapper = this.scrollWrapper
2732
const tagList = this.$parent.$refs.tag
2833
2934
let firstTag = null
@@ -44,6 +49,7 @@ export default {
4449
const currentIndex = tagList.findIndex(item => item === currentTag)
4550
const prevTag = tagList[currentIndex - 1]
4651
const nextTag = tagList[currentIndex + 1]
52+
4753
// the tag's offsetLeft after of nextTag
4854
const afterNextTagOffsetLeft = nextTag.$el.offsetLeft + nextTag.$el.offsetWidth + tagAndTagSpacing
4955

src/views/layout/components/TagsView.vue renamed to src/views/layout/components/TagsView/index.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</template>
2727

2828
<script>
29-
import ScrollPane from '@/components/ScrollPane'
29+
import ScrollPane from './ScrollPane'
3030
import { generateTitle } from '@/utils/i18n'
3131
import path from 'path'
3232
@@ -90,7 +90,6 @@ export default {
9090
}
9191
}
9292
})
93-
9493
return tags
9594
},
9695
initTags() {
@@ -115,12 +114,10 @@ export default {
115114
for (const tag of tags) {
116115
if (tag.to.path === this.$route.path) {
117116
this.$refs.scrollPane.moveToTarget(tag)
118-
119117
// when query is different then update
120118
if (tag.to.fullPath !== this.$route.fullPath) {
121119
this.$store.dispatch('updateVisitedView', this.$route)
122120
}
123-
124121
break
125122
}
126123
}
@@ -178,8 +175,8 @@ export default {
178175
} else {
179176
this.left = left
180177
}
181-
this.top = e.clientY
182178
179+
this.top = e.clientY
183180
this.visible = true
184181
this.selectedTag = tag
185182
},

src/views/layout/components/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { default as Navbar } from './Navbar'
22
export { default as Sidebar } from './Sidebar/index.vue'
3-
export { default as TagsView } from './TagsView'
3+
export { default as TagsView } from './TagsView/index.vue'
44
export { default as AppMain } from './AppMain'

0 commit comments

Comments
 (0)