- 跨函数用this
- 一个变量如果只用到一次name就无需声明变量直接使用
let bar = this.$refs.scrollBar
let barHeight = (this.parentHeight * this.parentHeight / this.childHeight)
this.barHeight = barHeight
bar.style.height = barHeight + 'px'
let y = -(this.contentY * this.parentHeight / this.childHeight)
this.scrollMoveY = y + 'px'
this.scrollBarY = y
上面的bar只用到了一次,所以可以直接用
this.$refs.scrollBar.style.height = barHeight + 'px'














网友评论