mounted() {
let recordExecutionsNum = 0;
let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
let element = document.getElementById('asset-list-search')
this.observer = new MutationObserver( (mutationList) => {
for (let mutation of mutationList) {
console.log('mutation', mutation)
}
let height = getComputedStyle(element).getPropertyValue('height')
if (height === this.recordOldValue.height) return
this.recordOldValue = {
height
}
height = +height.replace('px', '')
let clientHeight = document.getElementsByClassName('cardlayout-content')[0].clientHeight - 120
this.height = clientHeight || 500 // 动态设置高度
this.recordExecutionsNum += 1
})
this.observer.observe(element, { attributes: true, characterData: true })
},
参考地址:js监听div元素的宽高变化