getElementTop (el) {// 获取ele元素距离父元素的offsetTop值let actualTop = el.offsetTop;// 获取该元素的有定位的父级元素let current = el.offsetParent;while (current !== null) {// 判断当前元素是否循环到html根节点了// offsetTop值循环相加actualTop += current.offsetTop;// 当current为html根元素时,current.offsetParent值为nullcurrent = current.offsetParent}// 得到offsetTop值相加的值之和,即元素距离顶部的高度return actualTop - 300},
this.$refs.typeTable('typeTable为父元素').dom.scrollTop = this.getElementTop(document.getElementById('子元素'))