vue2.0和mintui-infiniteScroll結(jié)合如何實現(xiàn)無線滾動加載
vue2.0和mintui-infiniteScroll實現(xiàn)無線滾動加載
<template lang="html"> <div class="main"> <div class='list-box'> <ul v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-immediate-check="true" infinite-scroll-distance="40"> <li v-for="(item ,index) in list" :key="index"> {{item.title}} </li> </ul> <!--顯示加載中狀態(tài)--> <div class="loading-box" v-if="loading"> <mt-spinner type="fading-circle" class="loading-more" color="#0188fd"></mt-spinner> </div> <div class="no-more" v-if="noMore">親,已經(jīng)到底了哦!</div> </div> </div> </template>
<script> import { InfiniteScroll , Spinner } from 'mint-ui'; export default { components: { 'mt-spinner':Spinner, }, data() { return { list: [], pagesNum: 1,//總頁數(shù) loading: false, // 加載中轉(zhuǎn)圈 noMore: false, // 是否還有更多 endTime: "", page: { access_token: this.$route.query.access_token, planId: this.$route.query.id, pageNumber: 1, pageSize: 20, } } }, created() { this.initData(); }, mounted() { }, methods: { initData: function(type) { this.loading = true axios.get("xxx", { params: this.page }) .then((data) => { if (type === 'loadMore') { this.list = this.list.concat(data.data.data.list); } else { this.list = data.data.data.list; } // 設(shè)置分頁 this.pagesNum = data.data.data.pages; //總頁數(shù) this.loading = false; }) .catch(function(err) { console.log(err); }) }, loadMore:function() { this.page.pageNumber += 1 // 增加分頁 this.loading = true // 加載中 if(this.page.pageNumber <= this.pagesNum){ //加載數(shù)據(jù) setTimeout(()=>{ this.initData('loadMore') },200) }else{ this.noMore = true // 顯示沒有更多了 this.loading = false // 關(guān)閉加載中 return false } } } } </script>
<style> .list-box { max-height:calc(100% - 1.8rem); //必須有高度 overflow-y: auto; -webkit-overflow-scrolling: touch; } .list-box ul{ width:100%; } .list-box ul li{ width: 100%; height: 0.55rem; @include flexbox(); @include justify-content(space-between); border-bottom: 1px solid #e4e4e4; } </style>
vue使用mint-ui的Infinite scroll(無線滾動)報錯
MutationObserver': parameter 1 is not of type 'Node'." * Failed
在Vue里面使用mint-ui的Infinite scroll無線滾動,按照配置寫完之后,發(fā)現(xiàn)控制臺里報錯了。
如下錯誤信息:
Error in directive infinite-scroll inserted hook: “TypeError: Failed to execute ‘observe’ on ‘MutationObserver’: parameter 1 is not of type ‘Node’.”
Failed to execute ‘observe’ on ‘MutationObserver’: parameter 1 is not of type ‘Node’.
解決方法
給使用這個組件的元素設(shè)置height和overflow
<div class="wrap" v-infinite-scroll = "loadMore" infinite-scroll-disabled = "loading" infinite-scroll-distance = "10" ></div>
.wrap { height: 100vh; overflow-y: auto; }
然后控制臺就不會報錯了。然而官網(wǎng)并沒有寫這條非常重要的信息。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue 關(guān)閉瀏覽器窗口的時候,清空localStorage的數(shù)據(jù)示例
今天小編就為大家分享一篇vue 關(guān)閉瀏覽器窗口的時候,清空localStorage的數(shù)據(jù)示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11vue?this.$refs.xxx報錯undefined問題及解決
這篇文章主要介紹了vue?this.$refs.xxx報錯undefined問題及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03vue.js樣式布局Flutter業(yè)務(wù)開發(fā)常用技巧
這篇文章主要為大家介紹了vue.js樣式布局Flutter業(yè)務(wù)開發(fā)中的常用技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪2021-11-11Vue數(shù)據(jù)與事件綁定以及Class和Style的綁定詳細講解
這篇文章主要介紹了Vue數(shù)據(jù)與事件綁定以及Class和Style的綁定,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-01-01vue 點擊其他區(qū)域關(guān)閉自定義div操作
這篇文章主要介紹了vue 點擊其他區(qū)域關(guān)閉自定義div操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07