最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Vant框架list組件遇到的坑及解決

 更新時(shí)間:2022年04月25日 15:21:01   作者:木末回春風(fēng)  
這篇文章主要介紹了使用Vant框架list組件遇到的坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

使用Vant框架list組件的坑

介紹

Vant 是有贊前端團(tuán)隊(duì)開源的移動(dòng)端組件庫,于 2017 年開源,已持續(xù)維護(hù) 4 年時(shí)間。

Vant 對(duì)內(nèi)承載了有贊所有核心業(yè)務(wù),對(duì)外服務(wù)十多萬開發(fā)者,是業(yè)界主流的移動(dòng)端組件庫之一。

特性

  • 提供 60 多個(gè)高質(zhì)量組件,覆蓋移動(dòng)端各類場(chǎng)景
  • 性能極佳,組件平均體積不到 1kb(min+gzip)
  • 單元測(cè)試覆蓋率 90%+,提供穩(wěn)定性保障
  • 完善的中英文文檔和示例
  • 支持 Vue 2 & Vue 3
  • 支持按需引入
  • 支持主題定制
  • 支持國際化
  • 支持 TypeScript
  • 支持 SSR

快速配置和具體介紹請(qǐng)去官方文檔,Vant框架在Github上點(diǎn)贊眾多,用起來發(fā)現(xiàn)還是很好用的,強(qiáng)力推薦

聊一下使用list組件遇到的坑

官方文檔的實(shí)例代碼是這樣的:

<van-list
  v-model="loading"
  :finished="finished"
  finished-text="沒有更多了"
  @load="onLoad"
>
  <van-cell v-for="item in list" :key="item" :title="item" />
</van-list>
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    onLoad() {
      // 異步更新數(shù)據(jù)
      // setTimeout 僅做示例,真實(shí)場(chǎng)景中一般為 ajax 請(qǐng)求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }
        // 加載狀態(tài)結(jié)束
        this.loading = false;
        // 數(shù)據(jù)全部加載完成
        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },
  },
};

效果圖片:

可是!你復(fù)制代碼,發(fā)現(xiàn),發(fā)現(xiàn)完全不好用!這個(gè)定時(shí)任務(wù)簡直看不懂,觸底加載簡直毫無邏輯,通過幾個(gè)小時(shí)的研究,發(fā)現(xiàn)問題所在居然是CSS!對(duì),你沒有聽錯(cuò)!是CSS導(dǎo)致的!

下方代碼,重點(diǎn)看css部分,JS部分,記住settimeout不要去掉,不要相信他的注釋,業(yè)務(wù)寫在settimeout里就可以了

解釋一下這個(gè)css的含義,就是van-list需要給他定義一個(gè)高度,并且滾動(dòng)自適應(yīng),這樣在不填滿高度或者是滾動(dòng)觸底的時(shí)候就可以完美的觸發(fā)onLoad時(shí)間了,這里還有一個(gè)重點(diǎn)!就是van-list的父級(jí)也要定義一下高度,不然也是不行的!

至于業(yè)務(wù)一定要在settimeout中寫業(yè)務(wù)才能有效,了解的大佬看到了幫忙解釋一下,不是很明白

<div class="txtc" style="height: 100%; position: fixed; width: 100%">
	<van-list style="height:100%;width:100%;overflow-y:auto;"
	        v-model="loading"
	        :finished="finished"
	        finished-text="沒有更多了"
	        @load="onLoad"
	      >
	        <div class="divinfo" v-for="item in tableData" :key="item.sid"></div>
	</van-list>
</div>

vant中van-list的使用

van-list里面的元素不能有float樣式,否則會(huì)連續(xù)觸發(fā) load 事件

原代碼

<template>
? <div class="about">
? ? <van-tabs v-model="active" sticky @change="getTypeDate">
? ? ? <van-tab v-for="(tab) in typeList" :title="tab.name" :key="tab.id">
? ? ? ? <div :style="{height: contentHeight}" class="pic-content">
? ? ? ? ? <van-list
? ? ? ? ? ? :finished="finished"
? ? ? ? ? ? :finished-text="finishedText"
? ? ? ? ? ? v-model="loading"
? ? ? ? ? ? :offset="10"
? ? ? ? ? ? :immediate-check="false"
? ? ? ? ? ? @load="getserviceList"
? ? ? ? ? >
? ? ? ? ? <!------------------------------------------------- 修改前代碼 --------------------------------------------->
? ? ? ? ? ? ? /*<div
? ? ? ? ? ? ? ? class="pic-box"
? ? ? ? ? ? ? ? v-for="(serve) in serviceList"
? ? ? ? ? ? ? ? :key="serve.id"
? ? ? ? ? ? ? ? @click="router(serve)"
? ? ? ? ? ? ? >
? ? ? ? ? ? ? ? <div class="pic-item">
? ? ? ? ? ? ? ? ? <img
? ? ? ? ? ? ? ? ? ? v-if="serve.picturePath"
? ? ? ? ? ? ? ? ? ? :src="$BASE_PICTUREPATH_URL + serve.picturePath.split(',')[0]"
? ? ? ? ? ? ? ? ? >
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <p>{{serve.name}}</p>
? ? ? ? ? ? ? ? <p class="price-red">¥{{serve.price}}</p>
? ? ? ? ? ? ? </div>*/
? ? ? ? ? ? ? <!------------------------------------------------- 修改前代碼 --------------------------------------------->
? ? ? ? ? </van-list>
? ? ? ? </div>
? ? ? </van-tab>
? ? </van-tabs>
? </div>
</template>
<script>
import { Tab, Tabs, List, Cell, Row, Col } from "vant";
import { FetchServeType, FetchServeList } from "../apis/serve.js";
export default {
? data() {
? ? return {
? ? ? active: 0,
? ? ? typeList: [],
? ? ? serviceList: [],
? ? ? type: "",
? ? ? finishedText: "",
? ? ? finished: false,
? ? ? pageNum: 1,
? ? ? pageSize: 10,
? ? ? contentHeight: 0,
? ? ? loading: false
? ? };
? },
? mounted() {
? ? this.getOrderStyle();
? ? this.contentHeight = document.documentElement.clientHeight - 66 - 40 + "px";
? },
? methods: {
? ? async getOrderStyle() {
? ? ? let res = await FetchServeType();
? ? ? if (res.data && res.data.success) {
? ? ? ? this.typeList = res.data.data;
? ? ? ? this.type = res.data.data[0].name;
? ? ? ? this.getTypeDate();
? ? ? }
? ? },
? ? getTypeDate() {
? ? ? this.pageNum = 1;
? ? ? this.type = this.typeList[this.active].name;
? ? ? this.serviceList = [];
? ? ? this.finishedText = "";
? ? ? this.finished = false;
? ? ? this.getserviceList();
? ? },
? ? async getserviceList() {
? ? ? let toast = this.$toast.loading({
? ? ? ? mask: true,
? ? ? ? message: "加載中..."
? ? ? });
? ? ? const { type, pageNum, pageSize } = this;
? ? ? let params = {
? ? ? ? type,
? ? ? ? pageNum,
? ? ? ? pageSize
? ? ? };
? ? ? let res = await FetchServeList(params);
? ? ? this.loading = false;
? ? ? toast.close();
? ? ? if (res.data && res.data.success) {
? ? ? ? let list = (res.data.data && res.data.data.list) || [];
? ? ? ? if (pageNum > 1) {
? ? ? ? ? this.serviceList = [...this.serviceList, ...list];
? ? ? ? } else {
? ? ? ? ? this.serviceList = list;
? ? ? ? }
? ? ? ? // 如果當(dāng)前頁數(shù) = 總頁數(shù),則已經(jīng)沒有數(shù)據(jù)
? ? ? ? if (res.data.data.pageNum === res.data.data.pages) {
? ? ? ? ? this.finished = true;
? ? ? ? ? this.finishedText = "- 沒有更多了-";
? ? ? ? }
? ? ? ? // 如果總頁數(shù)大于當(dāng)前頁碼,頁碼+1
? ? ? ? if (res.data.data.pages > pageNum) {
? ? ? ? ? this.pageNum++;
? ? ? ? }
? ? ? }
? ? ? console.log("FetchServeList: ", this.serviceList);
? ? }
? }
};
</script>
<style lang="scss" scoped>
.pic-content {
? overflow-y: scroll;
? -webkit-overflow-scrolling: touch;
? .pic-box {
? /****************************修改前代碼***************************/
? ? background-color: #fff;
? ? overflow: hidden;
? ? break-inside: avoid;
? ? box-sizing: border-box;
? ? margin-bottom: 0.7rem;
? ? padding: 0.8rem;
? ? width: 48%;
? ? height: 16rem;
? ? ~~float: left;~~ /**************不能有float樣式*************/
? ? margin: 1%;
? ? border-radius: 4px;
? ? ?/****************************修改前代碼***************************/
? ? p:nth-of-type(1) {
? ? ? padding: 0.8rem 0;
? ? }
? ? p:nth-of-type(2) {
? ? ? color: red;
? ? }
? ? .pic-item {
? ? ? height: 11rem;
? ? ? flex-direction: column;
? ? ? justify-content: center;
? ? ? overflow: hidden;
? ? ? img {
? ? ? ? width: 100%;
? ? ? ? height: auto;
? ? ? ? border-radius: 4px;
? ? ? }
? ? }
? }
}
</style>

// 修改后代碼(注釋部分為修改后代碼)

<template>
? <div class="about">
? ? <van-tabs v-model="active" sticky @change="getTypeDate">
? ? ? <van-tab v-for="(tab) in typeList" :title="tab.name" :key="tab.id">
? ? ? ? <div :style="{height: contentHeight}" class="pic-content">
? ? ? ? ? <van-list
? ? ? ? ? ? :finished="finished"
? ? ? ? ? ? :finished-text="finishedText"
? ? ? ? ? ? v-model="loading"
? ? ? ? ? ? :offset="10"
? ? ? ? ? ? :immediate-check="false"
? ? ? ? ? ? @load="getserviceList"
? ? ? ? ? >
? ? ? ? ? <!------------------------------------------------- 修改后代碼 --------------------------------------------->
? ? ? ? ? ? /*<van-row>
? ? ? ? ? ? ? <van-col
? ? ? ? ? ? ? ? span="12"
? ? ? ? ? ? ? ? class="pic-box"
? ? ? ? ? ? ? ? v-for="(serve) in serviceList"
? ? ? ? ? ? ? ? :key="serve.id"
? ? ? ? ? ? ? ? @click="router(serve)"
? ? ? ? ? ? ? >
? ? ? ? ? ? ? ? <div class="pic-item">
? ? ? ? ? ? ? ? ? <img
? ? ? ? ? ? ? ? ? ? v-if="serve.picturePath"
? ? ? ? ? ? ? ? ? ? :src="$BASE_PICTUREPATH_URL + serve.picturePath.split(',')[0]"
? ? ? ? ? ? ? ? ? >
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? <p>{{serve.name}}</p>
? ? ? ? ? ? ? ? <p class="price-red">¥{{serve.price}}</p>
? ? ? ? ? ? ? </van-col>
? ? ? ? ? ? </van-row>*/
? ? ? ? ? ? <!------------------------------------------------- 修改后代碼 --------------------------------------------->
? ? ? ? ? </van-list>
? ? ? ? </div>
? ? ? </van-tab>
? ? </van-tabs>
? </div>
</template>
<script>
import { Tab, Tabs, List, Cell, Row, Col } from "vant";
import { FetchServeType, FetchServeList } from "../apis/serve.js";
export default {
? data() {
? ? return {
? ? ? active: 0,
? ? ? typeList: [],
? ? ? serviceList: [],
? ? ? type: "",
? ? ? finishedText: "",
? ? ? finished: false,
? ? ? pageNum: 1,
? ? ? pageSize: 10,
? ? ? contentHeight: 0,
? ? ? loading: false
? ? };
? },
? mounted() {
? ? this.getOrderStyle();
? ? this.contentHeight = document.documentElement.clientHeight - 66 - 40 + "px";
? },
? methods: {
? ? async getOrderStyle() {
? ? ? let res = await FetchServeType();
? ? ? if (res.data && res.data.success) {
? ? ? ? this.typeList = res.data.data;
? ? ? ? this.type = res.data.data[0].name;
? ? ? ? this.getTypeDate();
? ? ? }
? ? },
? ? getTypeDate() {
? ? ? this.pageNum = 1;
? ? ? this.type = this.typeList[this.active].name;
? ? ? this.serviceList = [];
? ? ? this.finishedText = "";
? ? ? this.finished = false;
? ? ? this.getserviceList();
? ? },
? ? async getserviceList() {
? ? ? let toast = this.$toast.loading({
? ? ? ? mask: true,
? ? ? ? message: "加載中..."
? ? ? });
? ? ? const { type, pageNum, pageSize } = this;
? ? ? let params = {
? ? ? ? type,
? ? ? ? pageNum,
? ? ? ? pageSize
? ? ? };
? ? ? let res = await FetchServeList(params);
? ? ? this.loading = false;
? ? ? toast.close();
? ? ? if (res.data && res.data.success) {
? ? ? ? let list = (res.data.data && res.data.data.list) || [];
? ? ? ? if (pageNum > 1) {
? ? ? ? ? this.serviceList = [...this.serviceList, ...list];
? ? ? ? } else {
? ? ? ? ? this.serviceList = list;
? ? ? ? }
? ? ? ? // 如果當(dāng)前頁數(shù) = 總頁數(shù),則已經(jīng)沒有數(shù)據(jù)
? ? ? ? if (res.data.data.pageNum === res.data.data.pages) {
? ? ? ? ? this.finished = true;
? ? ? ? ? this.finishedText = "- 沒有更多了-";
? ? ? ? }
? ? ? ? // 如果總頁數(shù)大于當(dāng)前頁碼,頁碼+1
? ? ? ? if (res.data.data.pages > pageNum) {
? ? ? ? ? this.pageNum++;
? ? ? ? }
? ? ? }
? ? ? console.log("FetchServeList: ", this.serviceList);
? ? }
? }
};
</script>
<style lang="scss" scoped>
.pic-content {
? overflow-y: scroll;
? -webkit-overflow-scrolling: touch;
? .pic-box {
? /************************ 修改后代碼**************************/
? ?background-color: #fff;
? ? overflow: hidden;
? ? box-sizing: border-box;
? ? margin-bottom: 0.7rem;
? ? padding: 0.8rem;
? ? height: 16rem;
? ? border-radius: 4px;
? ? /************************ 修改后代碼************************ **/
? ? p:nth-of-type(1) {
? ? ? padding: 0.8rem 0;
? ? }
? ? p:nth-of-type(2) {
? ? ? color: red;
? ? }
? ? .pic-item {
? ? ? height: 11rem;
? ? ? flex-direction: column;
? ? ? justify-content: center;
? ? ? overflow: hidden;
? ? ? img {
? ? ? ? width: 100%;
? ? ? ? height: auto;
? ? ? ? border-radius: 4px;
? ? ? }
? ? }
? }
}
</style>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue項(xiàng)目同時(shí)兼容pc和移動(dòng)端的解決方式

    vue項(xiàng)目同時(shí)兼容pc和移動(dòng)端的解決方式

    我們經(jīng)常在項(xiàng)目中會(huì)有支持pc與手機(jī)端需求,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目同時(shí)兼容pc和移動(dòng)端的解決方式,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-10-10
  • Vue3中的element-plus表格實(shí)現(xiàn)代碼

    Vue3中的element-plus表格實(shí)現(xiàn)代碼

    這篇文章主要介紹了Vue3中的element-plus表格實(shí)現(xiàn)代碼,用組件屬性實(shí)現(xiàn)跳轉(zhuǎn)路由,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-05-05
  • Vue動(dòng)畫之第三方類庫實(shí)現(xiàn)動(dòng)畫方式

    Vue動(dòng)畫之第三方類庫實(shí)現(xiàn)動(dòng)畫方式

    這篇文章主要介紹了Vue動(dòng)畫之第三方類庫實(shí)現(xiàn)動(dòng)畫方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue中echarts@4.9版本,地圖的使用方式

    vue中echarts@4.9版本,地圖的使用方式

    這篇文章主要介紹了vue中echarts@4.9版本地圖的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • vue清除瀏覽器全部cookie的問題及解決方法(絕對(duì)有效!)

    vue清除瀏覽器全部cookie的問題及解決方法(絕對(duì)有效!)

    最近項(xiàng)目要實(shí)現(xiàn)關(guān)閉瀏覽器清除用戶緩存的功能,下面這篇文章主要給大家介紹了關(guān)于vue清除瀏覽器全部cookie的問題及解決方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • 淺談VUE項(xiàng)目打包后運(yùn)行頁面一片白問題

    淺談VUE項(xiàng)目打包后運(yùn)行頁面一片白問題

    本文主要介紹了淺談VUE項(xiàng)目打包后運(yùn)行頁面一片白問題,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2023-01-01
  • vue3實(shí)現(xiàn)動(dòng)態(tài)添加路由

    vue3實(shí)現(xiàn)動(dòng)態(tài)添加路由

    這篇文章主要介紹了vue3實(shí)現(xiàn)動(dòng)態(tài)添加路由方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • VUE 常規(guī)截取和特殊字符之前之后截取(實(shí)例代碼)

    VUE 常規(guī)截取和特殊字符之前之后截取(實(shí)例代碼)

    這篇文章主要介紹了VUE 常規(guī)截取和特殊字符之前之后截取,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-10-10
  • Vue拖動(dòng)截圖功能的簡單實(shí)現(xiàn)方法

    Vue拖動(dòng)截圖功能的簡單實(shí)現(xiàn)方法

    最近項(xiàng)目上要做一個(gè)車牌識(shí)別的功能,就需要做拖動(dòng)截圖功能了,因?yàn)榍岸问莢ue,所以下面這篇文章主要給大家介紹了關(guān)于Vue拖動(dòng)截圖功能的簡單實(shí)現(xiàn)方法,需要的朋友可以參考下
    2021-07-07
  • Vue采用異步渲染的原理分析

    Vue采用異步渲染的原理分析

    對(duì)于Vue為何采用異步渲染,簡單來說就是為了提升性能,因?yàn)椴徊捎卯惒礁拢诿看胃聰?shù)據(jù)都會(huì)對(duì)當(dāng)前組件進(jìn)行重新渲染,為了性能考慮,Vue會(huì)在本輪數(shù)據(jù)更新后,再去異步更新視圖,本文主要通過幾個(gè)實(shí)例給大家介紹一下Vue為何采用異步渲染,需要的朋友可以參考下
    2023-06-06

最新評(píng)論

隆子县| 新泰市| 宜州市| 成都市| 若尔盖县| 神农架林区| 无极县| 南宁市| 娄烦县| 万年县| 鄯善县| 东海县| 樟树市| 濮阳市| 新密市| 巴南区| 文成县| 广丰县| 新乡县| 佳木斯市| 龙南县| 万盛区| 南漳县| 平度市| 呼玛县| 乌兰浩特市| 章丘市| 舟山市| 任丘市| 潜江市| 开化县| 攀枝花市| 会理县| 天长市| 康保县| 思南县| 大宁县| 甘德县| 辉县市| 威远县| 和田县|