解决vant框架做H5时踩过的坑(下拉刷新、上拉加载等) – haodro.com 您所在的位置:网站首页 vant中文官网 解决vant框架做H5时踩过的坑(下拉刷新、上拉加载等) – haodro.com

解决vant框架做H5时踩过的坑(下拉刷新、上拉加载等) – haodro.com

2023-03-15 21:52| 来源: 网络整理| 查看: 265

1. 页面在手机端不能上下滑动,在PC端浏览器正常滑动

说明:在设置了overflow:auto;属性的前提下,H5页面在PC端浏览器里展示可以上下滑动,在ios上可正常滑动,在安卓手机 上不能上下滑动;这现象并不是ios和安卓兼容性问题!

原因:设置了touch-action: none;这属性为局部或者全局属性,将这条属性注释即可正常滑动。

2.使用PullRefresh和List列表实现下拉刷新和上拉加载时出现的问题

问题1. 下拉刷新时在手机上,不论滑到任何位置,只要下拉就刷新

原因:滑动的区间设置错了,此时滑动的区间应是此组件的父盒子,我将overflow:scroll设置给了最外层盒子

问题2. 上拉加载时展示的列表始终只包含当前某一页,而不是当前页和加载出的那一页

原因:请求接口的参数不应该是current++,也就是不应该是当前页数+1,而是始终保持当前页数,请求的size=current*size

问题3. 下拉时,当数据很少的情况下,页面的最下面部分被遮住

原因:给van-list设置了height,且height: 80%,van-list必须设置高,否则无法滑动

解决办法:设置最小高:min-height: calc(100vh – 100px); overflow: hidden;

问题4.上拉加载时出现重复加载问题

van-list的属性finished触发时间错误,如果直接放在@load方法中,则会出现一直请求加载

解决办法:将finished=true放在请求接口返回数据的方法里,当当前页面数据大于等于返回的总条数,finished=true,显示加载完成,不再触发load加载事件。

注:附上下拉刷新、上拉加载部分的代码

data(){ return { isLoading: false, finished: false, loading: false, } }, methods:{ getVideoList() { getVideoList(this.current, this.selectDisposeStatus, this.searchValue).then(resp => { this.videoList = resp.data.records this.isVideoList = false if (this.videoList.length >= resp.data.total) { this.finished = true } }).catch(() => { this.error = true }) }, onRefresh() { this.current = 1 this.getVideoList() this.isLoading = false this.$toast('刷新成功') }, onLoadList() { this.current++ this.loading = false this.getVideoList() this.$toast('加载成功') }, }

补充知识:Vant与Element-ui出现Property ‘$notify’ must be of type ‘ElNotification’错误

遇到问题:

ERROR in /Users/oyo/projects/dataplatform/coconut/node_modules/vant/types/notify.d.ts 33:5 Subsequent property declarations must have the same type. Property ‘$notify’ must be of type ‘ElNotification’, but here has type ‘Notify’.

原因是两个组件库都在应用上添加了 $notify 方法;

解决方法是:只安装一个组件库, 另一个组件库按需引入

报错示例:

npm install vant element-ui

vant 和 element-ui 都有 $notify 方法, 会报错

import Vue from 'vue'; import Vant from 'vant'; import 'vant/lib/index.css'; import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(Vant); Vue.use(ElementUI);

解决方案:

import Vue from 'vue'; import Vant from 'vant'; import 'vant/lib/index.css'; // 按需引入你用到的组件, 而不是安装整个组件库 import ElButton from 'element-ui/lib/button'; import 'element-ui/lib/theme-chalk/button.css'; Vue.use(Vant); Vue.component('el-button', ElButton); tsconfig.json { "compilerOptions": { "paths": { // 指向正确的声明映射 "element-ui/lib/button": ["node_modules/element-ui/types/button"] } } }

以上这篇解决vant框架做H5时踩过的坑(下拉刷新、上拉加载等)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持呐喊教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有