解决vant框架做H5时踩过的坑(下拉刷新、上拉加载
1. 页面在手机端不能上下滑动,在PC端浏览器正常滑动
说明在设置了overflow:auto;属性的前提下,H5页面在PC端浏览器里展示可以上下滑动,在ios上可正常滑动,在安卓手机 上不能上下滑动;这现象并不是ios和安卓兼容性问题!
原因设置了touch-action: none;这属性为局部或者全局属性,将这条属性注释即可正常滑动。
2.使用PullRefresh和List列表实现下拉刷新和上拉加载时出现的问题
问题1. 下拉刷新时在手机上,不论滑到任何位置,只要下拉就刷新
原因滑动的区间设置错了,此时滑动的区间应是此组件的父盒子,我将overflow:scroll设置给了最外层盒子
问题2. 上拉加载时展示的列表始终只包含当前某一页,而不是当前页和加载出的那一页
原因请求接口的参数不应该是current++,也就是不应该是当前页数+1,而是始终保持当前页数,请求的size=currentsize
问题3. 下拉时,当数据很少的情况下,页面的最狼蚁网站SEO优化部分被遮住
原因给van-list设置了height,且height: 80%,van-list必须设置高,否则无法滑动
解决办法设置最小高min-height: calc(100vh - 100px); overflow: hidden;
问题4.上拉加载时出现重复加载问题
van-list的属性finished触发时间错误,如果直接放在@load方法中,则会出现一直请求加载
解决办法将finished=true放在请求接口返回数据的方法里,当当前页面数据大于等于返回的总条数,finished=true,显示加载完成,不再触发load加载事件。
注附上下拉刷新、上拉加载部分的代码
<template> <van-pull-refresh v-model="isLoading" :head-height="20" @refresh="onRefresh"> <van-list v-model="loading" :finished="finished" :offset="1" :immediate-check="false" :error.sync="error" finished-text="已全部加载完成" error-text="请求失败,点击重新加载" @load="onLoadList" > </van-list> </van-pull-refresh> </template>
<script> 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('加载成功') }, } </script>
补充知识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.ponent('el-button', ElButton);
tsconfig.json { "pilerOptions": { "paths": { // 指向正确的声明映射 "element-ui/lib/button": ["node_modules/element-ui/types/button"] } } }
以上这篇解决vant框架做H5时踩过的坑(下拉刷新、上拉加载等)就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- 甘肃哪有关键词排名优化购买方式有哪些
- 甘肃SEO如何做网站优化
- 河南seo关键词优化怎么做电话营销
- 北京SEO优化如何做QQ群营销
- 来宾百度关键词排名:提升您网站曝光率的关键
- 卢龙关键词优化:提升您网站排名的策略与技巧
- 山东网站优化的注意事项有哪些
- 四川整站优化怎样提升在搜索引擎中的排名
- 疏附整站优化:提升网站性能与用户体验的全新
- 海南seo主要做什么工作售后服务要做到哪些
- 荣昌百度网站优化:提升您网站的搜索引擎排名
- 河北seo网站排名关键词优化如何做SEO
- 江西优化关键词排名推广售后保障一般有哪些
- 古浪SEO优化:提升你的网站可见性
- 西藏网站排名优化怎么把网站排名在百度首页
- 如何提升阳东百度快照排名:详尽指南