Skip to content

Commit 609ad0a

Browse files
【vue-markdown组件无限更新循环报错解决,“you may have an infinite update loop in a component render function”】
1 parent a522349 commit 609ad0a

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

website/src/views/component/product.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default {
8989
},
9090
methods: {
9191
clearScroll() {
92-
let {observer} = this;
92+
let {observer} = this;
9393
if(observer) {
9494
document.querySelectorAll('h2[id]').forEach((section) => {
9595
observer.unobserve(section);
@@ -109,15 +109,27 @@ export default {
109109
this.observer = new IntersectionObserver((entries) => {
110110
entries.forEach((entry) => {
111111
let id = entry.target.getAttribute('id');
112+
let hrefContent = id;
112113
id = encodeURI(id);
113114
//intersectionRatio:目标元素出现在视窗的比例
114115
if (entry.intersectionRatio > 0) {
115116
if (document.querySelector(`li a[href="#${id}"]`)) {
117+
if(hrefContent !== "产品介绍"
118+
&& hrefContent !== "leaflet"
119+
&& hrefContent !== "cesium"
120+
&& hrefContent !== "mapboxgl"
121+
&& hrefContent !== "openlayers"
122+
&& hrefContent !== "vue组件开发"
123+
){
124+
document.querySelector('li a[href="#'+ encodeURI('产品介绍')+'"]').parentElement.classList.remove('active');
125+
}
116126
document.querySelector(`li a[href="#${id}"]`).parentElement.classList.add('active');
117127
}
118128
} else {
119129
if (document.querySelector(`li a[href="#${id}"]`)) {
120-
document.querySelector(`li a[href="#${id}"]`).parentElement.classList.remove('active');
130+
if(hrefContent.indexOf("产品介绍") < 0){
131+
document.querySelector(`li a[href="#${id}"]`).parentElement.classList.remove('active');
132+
}
121133
}
122134
}
123135
});
@@ -170,7 +182,6 @@ export default {
170182
resetHtml(mode, file, first) {
171183
this.loading = true;
172184
var self = this;
173-
174185
var url = this.getHtmlUrl(mode, file, first);
175186
axios.get(url)
176187
.then(response => {
@@ -207,7 +218,10 @@ export default {
207218
markdownRendered() {
208219
this.isContentFinish = true;
209220
if (this.isTocFinish && this.isContentFinish) {
210-
this.initScroll();
221+
// this.$nextTick(function () {
222+
// // this.initScroll();
223+
// })
224+
// this.initScroll();
211225
}
212226
this.$nextTick(() => {
213227
Prism.highlightAll();
@@ -219,7 +233,10 @@ export default {
219233
tocRendered() {
220234
this.isTocFinish = true;
221235
if (this.isTocFinish && this.isContentFinish) {
222-
this.initScroll();
236+
// this.initScroll();
237+
this.$nextTick(function () {
238+
this.initScroll();
239+
})
223240
}
224241
}
225242
}

website/src/views/guide/DevelopGuide.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default {
8888
},
8989
methods: {
9090
clearScroll() {
91-
let {observer} = this;
91+
let {observer} = this;
9292
if(observer) {
9393
document.querySelectorAll('h2[id]').forEach((section) => {
9494
observer.unobserve(section);
@@ -204,7 +204,7 @@ export default {
204204
markdownRendered() {
205205
this.isContentFinish = true;
206206
if (this.isTocFinish && this.isContentFinish) {
207-
this.initScroll();
207+
// this.initScroll();
208208
}
209209
this.$nextTick(() => {
210210
Prism.highlightAll();
@@ -216,7 +216,9 @@ export default {
216216
tocRendered() {
217217
this.isTocFinish = true;
218218
if (this.isTocFinish && this.isContentFinish) {
219-
this.initScroll();
219+
this.$nextTick(function () {
220+
this.initScroll();
221+
})
220222
}
221223
}
222224
}

0 commit comments

Comments
 (0)