Vue获取电脑及浏览器缩放比例
mounted() {
this.$nextTick(() => {
window.addEventListener("resize", () => {
});
});
},
detectZoom() {
let ratio = 0
const screen = window.screen
const ua = navigator.userAgent.toLowerCase()
if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio
} else if (~ua.indexOf('msie')) {
if (screen.deviceXDPI && screen.logicalXDPI) {
ratio = screen.deviceXDPI / screen.logicalXDPI
}
} else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
ratio = window.outerWidth / window.innerWidth
}
if (ratio) {
ratio = Math.round(ratio * 100)
}
return ratio
},
参考文档
el-table 自适应中间区域高度
<div ref="container">
<el-table :data="tableData" :height="tableHeight"></el-table>
</div>
tableHeight: 0,
timer: 0,
mounted () {
this.calHeight();
window.addEventListener('resize', this.onResize)
},
beforeDestroy () {
this.timer && clearTimeout(this.timer)
window.removeEventListener('resize', this.onResize)
},
calHeight () {
this.$nextTick(() => {
const rect = this.$refs.container.getBoundingClientRect()
this.tableHeight = rect.height - 100
})
},
onResize () {
this.timer && clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.calHeight()
}, 500)
},