|
|
@@ -155,40 +155,7 @@ export default {
|
|
|
mixins: [resize],
|
|
|
data() {
|
|
|
return {
|
|
|
- data: [
|
|
|
- 250000,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854,
|
|
|
- 5854
|
|
|
- ],
|
|
|
- vList: [],
|
|
|
+ data: [],
|
|
|
num: [
|
|
|
"one",
|
|
|
"two",
|
|
|
@@ -230,11 +197,9 @@ export default {
|
|
|
this.API.growing
|
|
|
.provinceRanking()
|
|
|
.then(res => {
|
|
|
- // console.log(res);
|
|
|
-
|
|
|
let arr = res.data;
|
|
|
arr.sort(function(a, b) {
|
|
|
- var x = b.totalMoney; //如果要从大到小,把x,y互换就好
|
|
|
+ var x = b.totalMoney;
|
|
|
var y = a.totalMoney;
|
|
|
return x < y ? -1 : x > y ? 1 : 0;
|
|
|
});
|
|
|
@@ -254,10 +219,19 @@ export default {
|
|
|
.catch(error => {
|
|
|
console.log(error);
|
|
|
});
|
|
|
- // this.show();
|
|
|
-
|
|
|
+ // 挂载全局滚动监听
|
|
|
window.addEventListener("scroll", this.lazyLoading, true);
|
|
|
},
|
|
|
+ // 新增:组件销毁钩子,清除定时器、移除滚动监听
|
|
|
+ beforeUnmount() {
|
|
|
+ // 清除自动滚动定时器
|
|
|
+ if (this.timer) {
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.timer = null;
|
|
|
+ }
|
|
|
+ // 移除window全局滚动监听,彻底断绝报错触发
|
|
|
+ window.removeEventListener("scroll", this.lazyLoading, true);
|
|
|
+ },
|
|
|
methods: {
|
|
|
fontSize(res) {
|
|
|
let docEl = document.documentElement,
|
|
|
@@ -271,66 +245,57 @@ export default {
|
|
|
},
|
|
|
|
|
|
lazyLoading() {
|
|
|
- // 滚动到底部,再加载的处理事件
|
|
|
- // 滚动高度;
|
|
|
- let noScrollBar = this.$refs.head;
|
|
|
+ // 增加防御判断:ref不存在直接终止执行
|
|
|
+ const noScrollBar = this.$refs.head;
|
|
|
+ if (!noScrollBar) return;
|
|
|
let scrollTop = noScrollBar.scrollTop;
|
|
|
- // console.log("scrollTop:" + scrollTop);
|
|
|
- //可视区高度
|
|
|
let clientHeight = noScrollBar.clientHeight;
|
|
|
- // console.log("clientHeight" + clientHeight);
|
|
|
- //滚动页面的高度
|
|
|
let scrollHeight = noScrollBar.scrollHeight;
|
|
|
- // console.log("scrollHeight" + scrollHeight);
|
|
|
|
|
|
if (scrollTop + clientHeight >= scrollHeight) {
|
|
|
- // document.getElementById("noScrollBar").scrollTop = 0
|
|
|
- // console.log("滚动到底部,触发");
|
|
|
setTimeout(() => {
|
|
|
- noScrollBar.scrollTop = 0;
|
|
|
+ // 再次防御判断
|
|
|
+ if (noScrollBar) noScrollBar.scrollTop = 0;
|
|
|
}, 2000);
|
|
|
}
|
|
|
- // let noScrollBar = this.$refs.head;
|
|
|
- // console.log(noScrollBar.scrollTop);
|
|
|
- // let clientH = this.$refs.clientH;
|
|
|
- // if (noScrollBar.scrollTop == clientH.clientHeight) {
|
|
|
- // noScrollBar.scrollTop = 0;
|
|
|
- // }
|
|
|
},
|
|
|
setIn(elNum, delay) {
|
|
|
- let noScrollBar = this.$refs.head;
|
|
|
- // let clientH = this.$refs.clientH;
|
|
|
+ const noScrollBar = this.$refs.head;
|
|
|
+ // 防御判断:元素不存在直接停止自动滚动
|
|
|
+ if (!noScrollBar) return;
|
|
|
|
|
|
this.timer = setInterval(() => {
|
|
|
- noScrollBar.scrollTop += 1;
|
|
|
- if (noScrollBar.scrollTop % elNum == 0 && noScrollBar.scrollTop != 0) {
|
|
|
+ // 循环内再次校验ref是否存在,防止中途页面销毁
|
|
|
+ if (!this.$refs.head) {
|
|
|
clearInterval(this.timer);
|
|
|
- if (noScrollBar.scrollTop == (this.maxList.length - 4) * elNum) {
|
|
|
- // noScrollBar.scrollTop = 0;
|
|
|
+ this.timer = null;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const bar = this.$refs.head;
|
|
|
+ bar.scrollTop += 1;
|
|
|
+ if (bar.scrollTop % elNum == 0 && bar.scrollTop != 0) {
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.timer = null;
|
|
|
+ if (bar.scrollTop == (this.maxList.length - 4) * elNum) {
|
|
|
+ setTimeout(() => {
|
|
|
+ if (bar) bar.scrollTop = 0;
|
|
|
+ // 仅组件存在时才重启滚动
|
|
|
+ if (this.$refs.head) this.setIn(elNum, delay);
|
|
|
+ }, delay);
|
|
|
+ } else {
|
|
|
setTimeout(() => {
|
|
|
- noScrollBar.scrollTop = 0;
|
|
|
- }, 2000);
|
|
|
- // console.log(11111);
|
|
|
+ if (this.$refs.head) this.setIn(elNum, delay);
|
|
|
+ }, delay);
|
|
|
}
|
|
|
- setTimeout(() => {
|
|
|
- this.setIn(elNum, delay);
|
|
|
- }, delay);
|
|
|
}
|
|
|
}, 10);
|
|
|
-
|
|
|
- // console.log(noScrollBar.scrollTop, (this.maxList.length - 4) * elNum);
|
|
|
},
|
|
|
enter(e) {
|
|
|
- // console.log(e);
|
|
|
- // e.target.firstChild.style = "display: block";
|
|
|
- e.target.children[1].style = "display: none";
|
|
|
- // console.log(e.target.children[1]);
|
|
|
+ e.target.children[1].style.display = "none";
|
|
|
},
|
|
|
-
|
|
|
leave(e) {
|
|
|
- e.target.firstChild.style = "display: none";
|
|
|
- e.target.children[1].style = "display: none";
|
|
|
- // console.log(e);
|
|
|
+ e.target.firstChild.style.display = "none";
|
|
|
+ e.target.children[1].style.display = "none";
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -517,4 +482,4 @@ export default {
|
|
|
animation-play-state: paused;
|
|
|
}
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|