36 lines
684 B
JavaScript
36 lines
684 B
JavaScript
import * as throttleUtil from '@/utils/throttle'
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
_clientWidth: '',
|
|
_clientHeight: ''
|
|
}
|
|
},
|
|
beforeMount() {
|
|
// 调用节流函数限制执行频率
|
|
var fn = throttleUtil.createOrUpdate(
|
|
this,
|
|
'_resizeHandler',
|
|
300,
|
|
'debounce'
|
|
)
|
|
window.addEventListener('resize', fn)
|
|
},
|
|
mounted() {
|
|
this._resizeHandler()
|
|
},
|
|
methods: {
|
|
_resizeHandler() {
|
|
this._clientWidth = document.documentElement.clientWidth
|
|
this._clientHeight = document.documentElement.clientHeight
|
|
if (this.resizeHandler) {
|
|
this.resizeHandler()
|
|
}
|
|
}
|
|
},
|
|
beforeDestroy() {
|
|
window.removeEventListener('resize', this._resizeHandler)
|
|
}
|
|
}
|