使用Element的InfiniteScroll 無限滾動(dòng)組件報(bào)錯(cuò)的解決
一、問題描述
在使用Element
的InfiniteScroll
無限滾動(dòng)時(shí)候出現(xiàn)以下錯(cuò)誤:
TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'
InfiniteScroll
的更多用法element官網(wǎng)
二、解決辦法
給需要使用 InfiniteScroll
的元素或者它的父級元素加上 overflow:auto;
屬性即可。
<template> <div class="home"> <div v-infinite-scroll="loadMore" v-for="i in count" class="infinite-list" :key="i">{{ i+1 }}</div> </div> </template> <script> export default { data() { return { count:5 } }, methods: { loadMore() { // this.count+=1; console.log('加載...') } } }; </script> <style lang="scss"> .home { .infinite-list{ width: 500px; height: 40px; line-height: 40px; background: lightblue; margin:10px; overflow:auto; // 加上該屬性即可。由瀏覽器定奪,如果內(nèi)容被修剪,瀏覽器就會(huì)顯示滾動(dòng)條以便查看其余內(nèi)容 } } </style>
三、注意事項(xiàng)
InfiniteScroll
無限滾動(dòng)組件, 滾動(dòng)至底部時(shí),加載更多數(shù)據(jù)。據(jù)官網(wǎng)描述其基礎(chǔ)用法:
給實(shí)現(xiàn)滾動(dòng)加載的元素(會(huì)出現(xiàn)滾動(dòng)條的元素)添加 v-infinite-scroll
屬性,屬性值是相應(yīng)的加載方法名,如loadMore
,即可實(shí)現(xiàn)滾動(dòng)到底部時(shí)觸發(fā)該loadMore
方法
注意屬性和css樣式的設(shè)置:
- 給設(shè)置了 v-infinite-scroll的元素或者其父元素設(shè)置高度如
height:200px;
,并讓其超出高度顯示滾動(dòng)條overflow:auto;
infinite-scroll-disabled="disabled"
,這里的disabled
是computed
里面的屬性,利用其控制是否繼續(xù)加載。當(dāng)disabled為true的時(shí)候,該加載函數(shù)loadMore
函數(shù)將不再被觸發(fā)。infinite-scroll-immediate
默認(rèn)為 true,即 立即執(zhí)行加載方法loadMore
,以防初始狀態(tài)下內(nèi)容無法撐滿容器。即loadMore會(huì)先執(zhí)行一次,這里設(shè)置false,是讓其初始不執(zhí)行,等滾動(dòng)到底部時(shí),再執(zhí)行該loadMore
方法。
<template> <div class="infinite-list-wrapper"> <ul class="list" v-infinite-scroll="loadMore" infinite-scroll-disabled="disabled" infinite-scroll-immediate="false"> <li v-for="i in count" class="list-item" :key="i">{{ i }}</li> </ul> <p v-if="loading">加載中...</p> <p v-if="noMore">沒有更多了</p> </div> </template> <script> export default { data() { return { count:5, loading: false }; }, computed: { noMore() { return this.count >= 20; }, disabled() { return this.loading || this.noMore; } }, methods: { loadMore() { console.log("加載...") this.loading = true; setTimeout(() => { this.count += 2; this.loading = false; }, 2000); } } }; </script> <style lang="scss"> .home { .infinite-list-wrapper{ height:200px; // 1. 指定高度 overflow: auto; // 2. 內(nèi)容超過指定高度 出現(xiàn)滾動(dòng)條 width: 500px; border:1px solid green; margin-top:120px; .list-item{ background: lightblue; margin:10px; height:30px; line-height: 30px; } } } </style>
到此這篇關(guān)于使用Element的InfiniteScroll 無限滾動(dòng)組件報(bào)錯(cuò)的解決的文章就介紹到這了,更多相關(guān)Element InfiniteScroll無限滾動(dòng)報(bào)錯(cuò)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue+vuex+json-seiver實(shí)現(xiàn)數(shù)據(jù)展示+分頁功能
這篇文章主要介紹了vue+vuex+json-seiver實(shí)現(xiàn)數(shù)據(jù)展示+分頁功能,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04Vue+Bootstrap實(shí)現(xiàn)簡易學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Vue+Bootstrap實(shí)現(xiàn)簡易學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-02-02Vue?3.0?項(xiàng)目創(chuàng)建過程及解決方案
這篇文章主要介紹了Vue?3.0?項(xiàng)目創(chuàng)建過程,首先要確保電腦上已安裝node.js,確保已安裝?Vue?CLI,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04vue2.0 computed 計(jì)算list循環(huán)后累加值的實(shí)例
下面小編就為大家分享一篇vue2.0 computed 計(jì)算list循環(huán)后累加值的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03vuejs在解析時(shí)出現(xiàn)閃爍的原因及防止閃爍的方法
這篇文章主要介紹了vuejs在解析時(shí)出現(xiàn)閃爍的原因及防止閃爍的方法,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-09-09