Skip to content

Commit eea6ea5

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

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

website/src/views/component/product.vue

Lines changed: 23 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,28 @@ 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:目标元素出现在视窗的比例
115+
114116
if (entry.intersectionRatio > 0) {
115117
if (document.querySelector(`li a[href="#${id}"]`)) {
118+
if(hrefContent !== "产品介绍"
119+
&& hrefContent !== "leaflet"
120+
&& hrefContent !== "cesium"
121+
&& hrefContent !== "mapboxgl"
122+
&& hrefContent !== "openlayers"
123+
&& hrefContent !== "vue组件开发"
124+
){
125+
document.querySelector('li a[href="#'+ encodeURI('产品介绍')+'"]').parentElement.classList.remove('active');
126+
}
116127
document.querySelector(`li a[href="#${id}"]`).parentElement.classList.add('active');
117128
}
118129
} else {
119130
if (document.querySelector(`li a[href="#${id}"]`)) {
120-
document.querySelector(`li a[href="#${id}"]`).parentElement.classList.remove('active');
131+
if(hrefContent.indexOf("产品介绍") < 0){
132+
document.querySelector(`li a[href="#${id}"]`).parentElement.classList.remove('active');
133+
}
121134
}
122135
}
123136
});
@@ -170,7 +183,6 @@ export default {
170183
resetHtml(mode, file, first) {
171184
this.loading = true;
172185
var self = this;
173-
174186
var url = this.getHtmlUrl(mode, file, first);
175187
axios.get(url)
176188
.then(response => {
@@ -207,7 +219,10 @@ export default {
207219
markdownRendered() {
208220
this.isContentFinish = true;
209221
if (this.isTocFinish && this.isContentFinish) {
210-
this.initScroll();
222+
// this.$nextTick(function () {
223+
// // this.initScroll();
224+
// })
225+
// this.initScroll();
211226
}
212227
this.$nextTick(() => {
213228
Prism.highlightAll();
@@ -219,7 +234,10 @@ export default {
219234
tocRendered() {
220235
this.isTocFinish = true;
221236
if (this.isTocFinish && this.isContentFinish) {
222-
this.initScroll();
237+
// this.initScroll();
238+
this.$nextTick(function () {
239+
this.initScroll();
240+
})
223241
}
224242
}
225243
}

website/src/views/guide/DevelopGuide.vue

Lines changed: 6 additions & 4 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);
@@ -105,7 +105,7 @@ export default {
105105
* 目标元素和视窗viewport的交集的变化的方法API
106106
* @type {IntersectionObserver}
107107
*/
108-
this.observer = new IntersectionObserver((entries) => {
108+
vm.observer = new IntersectionObserver((entries) => {
109109
entries.forEach((entry) => {
110110
let id = entry.target.getAttribute('id');
111111
id = encodeURI(id);
@@ -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)