uView ScrollList 横向滚动列表

该组件一般用于同时展示多个商品、分类的场景,也可以完成左右滑动的列表。

#平台差异说明

App(vue) App(nvue) H5 小程序

#基本使用

通过slot传入内容

<template>
    <u-scroll-list>
        <view v-for="(item, index) in list" :key="index">
            <image :src="item.thumb"></image>
        </view>
    </u-scroll-list>
</template>

<script>
    export default {
        data() {
            return {
                list: [{
                    thumb: "https://cdn.uviewui.com/uview/goods/1.jpg"
                }, {
                    thumb: "https://cdn.uviewui.com/uview/goods/2.jpg"
                }, {
                    thumb: "https://cdn.uviewui.com/uview/goods/3.jpg"
                }, {
                    thumb: "https://cdn.uviewui.com/uview/goods/4.jpg"
                }, {
                    thumb: "https://cdn.uviewui.com/uview/goods/5.jpg"
                }]
            }
        }
    }
</script>

copy

#指示器的使用

  • indicator 用于控制指示器是否显示

  • indicatorWidth 用于控制指示器整体的宽度

  • indicatorBarWidth 用于控制指示器滑块的宽度

  • indicatorColor 指示器的颜色

  • indicatorActiveColor 滑块的颜色

  • indicatorStyle 指示器的位置/样式控制

    <template> <u-scroll-list :indicator="indicator" indicatorColor="#fff0f0" indicatorActiveColor="#f56c6c"> <view v-for="(item, index) in list" :key="index"> <image :src="item.thumb"></image> </view> </u-scroll-list> </template> <script> export default { data() { return { indicator: true, list: [{ thumb: "https://cdn.uviewui.com/uview/goods/1.jpg" }, { thumb: "https://cdn.uviewui.com/uview/goods/2.jpg" }, { thumb: "https://cdn.uviewui.com/uview/goods/3.jpg" }, { thumb: "https://cdn.uviewui.com/uview/goods/4.jpg" }, { thumb: "https://cdn.uviewui.com/uview/goods/5.jpg" }] } } } </script>

copy

#兼容性与性能

  • 此组件是在nvue中引入bindingx,此库类似于微信小程序wxs,目的是让js运行在视图层,减少视图层和逻辑层的通信折损,在nvue中会有更好的体验。
  • 此组件是在APP-VUE、H5、小程序中使用的是wxs。
  • 其他平台则使用js完成。

当滑动到最左边/最右边时,uView提供了事件leftright可供调用,用于对列表滑动到端点处的业务实现。

<template>
    <u-scroll-list @right="right" @left="left">
        <view class="scroll-list" style="flex-direction: row;">
            <view
                    class="scroll-list__goods-item"
                    v-for="(item, index) in list"
                    :key="index"
                    :class="[(index === 9) && 'scroll-list__goods-item--no-margin-right']"
            >
                <image class="scroll-list__goods-item__image" :src="item.thumb"></image>
                <text class="scroll-list__goods-item__text">¥{{ item.price }}</text>
            </view>
            <view class="scroll-list__show-more">
                <text class="scroll-list__show-more__text">查看更多</text>
                <u-icon name="arrow-leftward" color="#f56c6c" size="12"></u-icon>
            </view>
        </view>
    </u-scroll-list>
</template>
<script>
export default {
	data() {
		return {
			list: [{
				price: '230.5',
                thumb: 'https://cdn.uviewui.com/uview/goods/1.jpg'
			}, {
				price: '74.1',
                thumb: 'https://cdn.uviewui.com/uview/goods/2.jpg'
			}, {
				price: '8457',
                thumb: 'https://cdn.uviewui.com/uview/goods/6.jpg'
			}, {
				price: '1442',
                thumb: 'https://cdn.uviewui.com/uview/goods/5.jpg'
			}, {
				price: '541',
                thumb: 'https://cdn.uviewui.com/uview/goods/2.jpg'
			}, {
				price: '234',
                thumb: 'https://cdn.uviewui.com/uview/goods/3.jpg'
			}, {
				price: '562',
                thumb: 'https://cdn.uviewui.com/uview/goods/4.jpg'
			}, {
				price: '251.5',
                thumb: 'https://cdn.uviewui.com/uview/goods/1.jpg'
			}]
		}
	},
	methods: {
		left() {
			console.log('left');
		},
		right() {
			console.log('right');
		}
	}
}
</script>

<style lang="scss">
.scroll-list {
	@include flex(column);

	&__goods-item {
		margin-right: 20px;

		&__image {
			width: 60px;
			height: 60px;
			border-radius: 4px;
		}

		&__text {
			color: #f56c6c;
			text-align: center;
			font-size: 12px;
			margin-top: 5px;
		}
	}

	&__show-more {
		background-color: #fff0f0;
		border-radius: 3px;
		padding: 3px 6px;
		@include flex(column);
		align-items: center;

		&__text {
			font-size: 12px;
			width: 12px;
			color: #f56c6c;
			line-height: 16px;
		}
	}
}
</style>
相关推荐
星之卡比*2 分钟前
前端知识点---库和包的概念
前端·harmonyos·鸿蒙
灵感__idea4 分钟前
Vuejs技术内幕:数据响应式之3.x版
前端·vue.js·源码阅读
烛阴7 分钟前
JavaScript 构造器进阶:掌握 “new” 的底层原理,写出更优雅的代码!
前端·javascript
Alan-Xia8 分钟前
使用jest测试用例之入门篇
前端·javascript·学习·测试用例
浪遏10 分钟前
面试官😏 :文本太长,超出部分用省略号 ,怎么搞?我:🤡
前端·面试
昕er12 分钟前
CefSharp 文件下载和保存功能-监听前端事件
前端
@PHARAOH17 分钟前
WHAT - Tree Shaking 的前提是 ES Module
前端·webpack·ecmascript
鱼樱前端24 分钟前
📚 Vue Router 4 核心知识点(Vue3技术栈)面试指南
前端·javascript·vue.js
计算机-秋大田28 分钟前
基于Spring Boot的宠物健康顾问系统的设计与实现(LW+源码+讲解)
java·vue.js·spring boot·后端·课程设计
食指Shaye30 分钟前
Chrome 中清理缓存的方法
前端·chrome·缓存