由于分页容器设置 fixed 定位,fixed 定位是相对 windows 定位的,所以fixed 定位的容器如果宽度设置 100% 的话就是 windows 的宽度,很不友好。
想设置分页的宽度为指定的宽度,但是这个宽度又不固定
mounted() {
this.setPaginationWidth()
window.addEventListener('resize', this.setPaginationWidth)
// 以下 this.$once() 代码其实也没有必要写
this.$once('hook:beforeDestroy', () => {
window.removeEventListener('resize', this.setPaginationWidth)
})
},
methods() {
setPaginationWidth() {
const rightDom = document.querySelector('.risk-detail-content-table') // 想要设置的分页的宽度的容器的dom
const paginationDom = document.querySelector('.el-pagination') // 分页dom
paginationDom.style.width = rightDom.offsetWidth + 'px'
},
}