perr: refine code
This commit is contained in:
		@@ -19,12 +19,21 @@ export default {
 | 
				
			|||||||
      return this.$refs.scrollContainer.$refs.wrap
 | 
					      return this.$refs.scrollContainer.$refs.wrap
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					  mounted() {
 | 
				
			||||||
 | 
					    this.scrollWrapper.addEventListener('scroll', this.emitScroll, true)
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  beforeDestroy() {
 | 
				
			||||||
 | 
					    this.scrollWrapper.removeEventListener('scroll', this.emitScroll)
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    handleScroll(e) {
 | 
					    handleScroll(e) {
 | 
				
			||||||
      const eventDelta = e.wheelDelta || -e.deltaY * 40
 | 
					      const eventDelta = e.wheelDelta || -e.deltaY * 40
 | 
				
			||||||
      const $scrollWrapper = this.scrollWrapper
 | 
					      const $scrollWrapper = this.scrollWrapper
 | 
				
			||||||
      $scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4
 | 
					      $scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    emitScroll() {
 | 
				
			||||||
 | 
					      this.$emit('scroll')
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    moveToTarget(currentTag) {
 | 
					    moveToTarget(currentTag) {
 | 
				
			||||||
      const $container = this.$refs.scrollContainer.$el
 | 
					      const $container = this.$refs.scrollContainer.$el
 | 
				
			||||||
      const $containerWidth = $container.offsetWidth
 | 
					      const $containerWidth = $container.offsetWidth
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div id="tags-view-container" class="tags-view-container">
 | 
					  <div id="tags-view-container" class="tags-view-container">
 | 
				
			||||||
    <scroll-pane ref="scrollPane" class="tags-view-wrapper">
 | 
					    <scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll">
 | 
				
			||||||
      <router-link
 | 
					      <router-link
 | 
				
			||||||
        v-for="tag in visitedViews"
 | 
					        v-for="tag in visitedViews"
 | 
				
			||||||
        ref="tag"
 | 
					        ref="tag"
 | 
				
			||||||
@@ -46,9 +46,6 @@ export default {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    routes() {
 | 
					    routes() {
 | 
				
			||||||
      return this.$store.state.permission.routes
 | 
					      return this.$store.state.permission.routes
 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    scrollWrapper() {
 | 
					 | 
				
			||||||
      return this.$refs.scrollPane.$refs.scrollContainer.$refs.wrap
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  watch: {
 | 
					  watch: {
 | 
				
			||||||
@@ -67,10 +64,6 @@ export default {
 | 
				
			|||||||
  mounted() {
 | 
					  mounted() {
 | 
				
			||||||
    this.initTags()
 | 
					    this.initTags()
 | 
				
			||||||
    this.addTags()
 | 
					    this.addTags()
 | 
				
			||||||
    this.scrollWrapper.addEventListener('scroll', this.closeMenu, true)
 | 
					 | 
				
			||||||
  },
 | 
					 | 
				
			||||||
  beforeDestroy() {
 | 
					 | 
				
			||||||
    document.removeEventListener('scroll', this.closeMenu)
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    isActive(route) {
 | 
					    isActive(route) {
 | 
				
			||||||
@@ -196,6 +189,9 @@ export default {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    closeMenu() {
 | 
					    closeMenu() {
 | 
				
			||||||
      this.visible = false
 | 
					      this.visible = false
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    handleScroll() {
 | 
				
			||||||
 | 
					      this.closeMenu()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user