randomImg() { if (document.body.getBoundingClientRect) { window.addEventListener('resize', this.resize) this.resize() } let randomNum = Math.ceil(Math.random() * 9) || '' let bgImg = `/static/images/logon_bg${randomNum}.jpg` this.bgImg = bgImg this.getImg() }, resize() { let bodySize = document.body.getBoundingClientRect() let w = bodySize.width let h = bodySize.height let flag = w / h > this.proportion && w > h
let bgSize = flag ? '100% auto' : 'auto 100%'
this.bgSize = bgSize }, getImg() { let img = document.createElement('img') let randomNum = Math.ceil(Math.random() * 9) || '' img.src = `/static/images/logon_bg${randomNum}.jpg` let that = this img.onload = function () { that.proportion = img.width / img.height that.resize() } },