位置: IT常识 - 正文

uniapp scroll-view基础用法

编辑:rootadmin
uniapp scroll-view基础用法 前言

推荐整理分享uniapp scroll-view基础用法,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

        在uniapp日常开发的过程中经常会有局部滚动的需求,而scroll-view组件正好可以满足这一需求。需注意在webview渲染的页面中,区域滚动的性能不及页面滚动。

纵向滚动

        将scroll-view组件中的属性scroll-y设定为true开启纵向滚动功能,给scroll-view设置一个高度,当内容高度大于scroll-view高度时即可开启滚动功能(内容高度小于scroll-view高度时无法体现滚动功能)

实现代码:

<template><view><scroll-view scroll-y="true" style="height: 700rpx;"><view v-for="(item,index) in 3" style="height: 500rpx;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"]}},methods: {}}</script><style></style>

效果图:

横向滚动

        将scroll-view组件中的属性scroll-x设定为true开启横向滚动功能,给scroll-view设置一个宽度,当内容宽度大于scroll-view宽度时即可开启滚动功能(内容宽度小于scroll-view宽度时无法体现滚动功能)

        注意:scroll-view本身的display:flex不生效、如果想实现display:flex功能,则可以给scroll-view加上white-space: nowrap,给内容容器加上display:inline-block

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;"><view v-for="(item,index) in 3" style="height: 500rpx;width: 100%;display: inline-block;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"]}},methods: {}}</script><style></style>

效果图:

 锚点定位uniapp scroll-view基础用法

        当我们已进入页面就需要滚动到某一个元素的时候,锚点定位就可以很好的帮助我们定位并滚动到指定位置

        将scroll-with-animation设定为true开启动画效果、对scroll-into-view进行动态绑定

        注意:scroll-into-view绑定的值得是字符串,使用其他类型则会报错

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;" scroll-with-animation="true" :scroll-into-view="'scroll'+scrollId"><view v-for="(item,index) in 3" style="height: 500rpx;width: 80%;display: inline-block;" :style="{ backgroundColor: colorList[index]}" :id="'scroll'+index">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"],scrollId:1}},methods: {}}</script><style></style>

效果图:

触底事件       

        在滑动的数据需要懒加载的时候,我们就需要通过用户滑动到底部时触发懒加载方法,通过绑定scrolltolower方法即可实现纵/横触底时触发懒加载方法

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;" @scrolltolower="onReachScollBottom"><view v-for="(item,index) in 3" style="height: 500rpx;width: 80%;display: inline-block;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"],}},methods: {onReachScollBottom(){uni.showToast({title:"触发了触底事件",duration:1500,icon:"none"})}}}</script><style></style>

 效果图:

 下拉刷新事件

        scroll-view组件也可以满足我们下拉刷新的需求、首先通过设置refresher-enabled为true开启下拉加载、动态绑定refresher-triggered对下拉加载的状态进行控制、绑定refresherrefresh触发下拉刷新事件

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;" refresher-enabled="true" :refresher-triggered="refresh" @refresherrefresh="onRefresh"><view v-for="(item,index) in 3" style="height: 500rpx;width: 80%;display: inline-block;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"],refresh: false}},methods: {onRefresh() {this.refresh= true;uni.showToast({title:"触发了下拉刷新",duration:1500,icon:"none"})// 这里不能直接让refresh直接为false,否则可能会发生下拉加载无法复位的情况setTimeout(() => {this.refresh = false;}, 500)}}}</script><style></style>

效果图:

 总结

        以上就是我整理的scroll-view的基础用法、想要了解更多的用法可以前往uniapp scroll-view部分进行了解

本文链接地址:https://www.jiuchutong.com/zhishi/299191.html 转载请保留说明!

上一篇:controller层,service层,mapper层,entity层的作用与联系。(controller层,service层,dao)

下一篇:和月薪5W的阿里程序员聊过后,才知道自己一直在打杂...(阿里月薪3万到手多少)

  • 交易性金融资产公允价值变动计入
  • 政府补助是否可以加计抵扣
  • 应付款为什么是负数
  • 总公司如何分配股份
  • 会计净额法和总额法
  • 小规模纳税人农产品进项税抵扣
  • 税收优惠有哪些类型
  • 计算企业所得税不得扣除的项目
  • 上市公司存货跌价准备怎么看
  • 经营利润所得税费用的计算公式
  • 税务开专票遇到四舍五入
  • 非居民企业股权转让协议
  • 收发差错率
  • 营改增后增值税暂行条例实施细则
  • 工程劳务公司的生产销售情况分析
  • 利润的三个计算口径
  • 多交的增值税可以抵所得税吗?
  • 支付知识产权服务费账务处理
  • 出口免税金额
  • window11系统怎么用
  • 利润分配会计处理时间
  • 报销冲借款是什么意思
  • linux系统开机黑屏怎么办
  • 先开票后发货怎么操作
  • PHP:oci_result()的用法_Oracle函数
  • php框架基础教程
  • 差旅费车票抵扣的相关规定
  • es5和es6的区别
  • vue2计算属性和vue3的计算属性的区别
  • mksysb命令
  • 合作社计提工资
  • 红冲费用如何处理
  • 待认证进项税额是二级科目还是三级科目
  • 变电所用电
  • 其他应收款可以直接平账吗
  • MongoDB中MapReduce编程模型使用实例
  • 商业汇票分为哪几种
  • 非流动资产处置损失计入什么科目
  • 企业促销费用项目有哪些
  • 私车公用必须是公司员工的车吗?
  • 小规模纳税人按1%
  • 补提去年累计折旧
  • 广告费收入如何填写增值税申报表
  • 文化传媒公司的主营业务
  • 营业利润为负数表示什么
  • 减免增值税记账
  • 上月计提少了怎么办
  • 基本工资和什么挂钩
  • 事业单位的非税收入账务处理
  • sql分页查询怎么实现
  • mysql 树状查询语句
  • 怎么提高windows7性能
  • w10预览版新功能
  • 为快捷方式建立快捷方式
  • ubuntu英文系统安装中文输入法
  • centos作用
  • win7老是自动开机启动是怎么回事啊
  • centos查询所有用户
  • linux中dhcp
  • xp清理系统的命令
  • win10安装win8双系统
  • sgmain.exe - sgmain是什么进程 有何作用
  • win7系统连不了蓝牙
  • jquery九宫格抽奖
  • 如何使用灭火器
  • perl \w
  • python爬虫框架怎么画
  • nodejs实现登录功能
  • Python 专题四 文件基础知识
  • linux 打包
  • shell函数返回多个值包含数组
  • js proto prototype
  • jQuery实现表格行和列的动态添加与删除方法【测试可用】
  • android面试题2019
  • 酒席发票
  • 请问地税是省直单位吗
  • 国税增值税申报怎么记账凭证填写
  • 湖北省税务局网站授权
  • 深圳国税税发票在哪里开
  • 不动产契税怎么计算出来的
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设