Merge branch 'hotfix/addEventListener'

Former-commit-id: af59e377b5a056f141a36d8c6fb3e52d9b36c327 [formerly af59e377b5a056f141a36d8c6fb3e52d9b36c327 [formerly af59e377b5a056f141a36d8c6fb3e52d9b36c327 [formerly af59e377b5a056f141a36d8c6fb3e52d9b36c327 [formerly 6570a63a861f97717c3bdb8233506ddde732b279 [formerly b2a703c4375c13ec76635c235777a1fe3fdf8031]]]]]
Former-commit-id: 70ee8c805423278ed5ac1788a76cb08c96e024c4
Former-commit-id: 0b69b49a5c7afb94858fbc0f62f3410bf97809ef
Former-commit-id: df7ecd62d3044fb372e893052ee616ba1e6e9e7d [formerly 439c32c8bb580e6704d5ceef36c6a9eca39f931d]
Former-commit-id: 889840260e4b92e6a4621dd6f09d9d5469a80aed
Former-commit-id: 183e11b31ba7c1da6b5a40dbc3bd798efbcd5ef0
Former-commit-id: f273c972a8c4b470205e7ce017dfac2bf4cacdda
Former-commit-id: 5bfcc89d1c844c2d2767827c4da43395857ecdc7
Former-commit-id: 97331f0b0090fa0da8f5c39a311434bb3904c0f6
This commit is contained in:
liyang
2018-09-19 16:00:08 +08:00
2 changed files with 15 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "d2-admin",
"version": "1.4.7",
"version": "1.4.8",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --open",

View File

@@ -20,6 +20,7 @@
</template>
<script>
import { throttle } from 'lodash'
import { mapState } from 'vuex'
import menuMixin from '../mixin/menu'
import d2LayoutMainMenuItem from '../components/menu-item/index.vue'
@@ -44,7 +45,8 @@ export default {
isScroll: false,
scrollWidth: 0,
contentWidth: 0,
currentTranslateX: 0
currentTranslateX: 0,
throttledCheckScroll: null
}
},
watch: {
@@ -68,10 +70,8 @@ export default {
this.currentTranslateX = this.contentWidth - this.scrollWidth
}
}
}
},
mounted () {
const checkScroll = () => {
},
checkScroll () {
let contentWidth = this.$refs.content.clientWidth
let scrollWidth = this.$refs.scroll.clientWidth
if (this.isScroll) {
@@ -105,14 +105,18 @@ export default {
})
}
}
},
mounted () {
// 初始化判断
checkScroll()
// 默认判断父元素和子元素的大小,以确定初始情况是否显示滚动
this.checkScroll()
// 全局窗口变化监听判断父元素和子元素的大小从而控制isScroll的开关
window.onresize = () => {
checkScroll()
}
this.throttledCheckScroll = throttle(this.checkScroll, 300)
window.addEventListener('resize', this.throttledCheckScroll)
},
beforeDestroy () {
// 取消监听
window.removeEventListener('resize', this.throttledCheckScroll)
}
}
</script>