当前位置:   article > 正文

uView ScrollList 横向滚动列表

uview scrolllist 横向滚动列表

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

#平台差异说明

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

#基本使用

通过slot传入内容

  1. <template>
  2. <u-scroll-list>
  3. <view v-for="(item, index) in list" :key="index">
  4. <image :src="item.thumb"></image>
  5. </view>
  6. </u-scroll-list>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. list: [{
  13. thumb: "https://cdn.uviewui.com/uview/goods/1.jpg"
  14. }, {
  15. thumb: "https://cdn.uviewui.com/uview/goods/2.jpg"
  16. }, {
  17. thumb: "https://cdn.uviewui.com/uview/goods/3.jpg"
  18. }, {
  19. thumb: "https://cdn.uviewui.com/uview/goods/4.jpg"
  20. }, {
  21. thumb: "https://cdn.uviewui.com/uview/goods/5.jpg"
  22. }]
  23. }
  24. }
  25. }
  26. </script>

copy

#指示器的使用

  • indicator 用于控制指示器是否显示
  • indicatorWidth 用于控制指示器整体的宽度
  • indicatorBarWidth 用于控制指示器滑块的宽度
  • indicatorColor 指示器的颜色
  • indicatorActiveColor 滑块的颜色
  • indicatorStyle 指示器的位置/样式控制
  1. <template>
  2. <u-scroll-list :indicator="indicator" indicatorColor="#fff0f0" indicatorActiveColor="#f56c6c">
  3. <view v-for="(item, index) in list" :key="index">
  4. <image :src="item.thumb"></image>
  5. </view>
  6. </u-scroll-list>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. indicator: true,
  13. list: [{
  14. thumb: "https://cdn.uviewui.com/uview/goods/1.jpg"
  15. }, {
  16. thumb: "https://cdn.uviewui.com/uview/goods/2.jpg"
  17. }, {
  18. thumb: "https://cdn.uviewui.com/uview/goods/3.jpg"
  19. }, {
  20. thumb: "https://cdn.uviewui.com/uview/goods/4.jpg"
  21. }, {
  22. thumb: "https://cdn.uviewui.com/uview/goods/5.jpg"
  23. }]
  24. }
  25. }
  26. }
  27. </script>

copy

#兼容性与性能

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

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

  1. <template>
  2. <u-scroll-list @right="right" @left="left">
  3. <view class="scroll-list" style="flex-direction: row;">
  4. <view
  5. class="scroll-list__goods-item"
  6. v-for="(item, index) in list"
  7. :key="index"
  8. :class="[(index === 9) && 'scroll-list__goods-item--no-margin-right']"
  9. >
  10. <image class="scroll-list__goods-item__image" :src="item.thumb"></image>
  11. <text class="scroll-list__goods-item__text">¥{{ item.price }}</text>
  12. </view>
  13. <view class="scroll-list__show-more">
  14. <text class="scroll-list__show-more__text">查看更多</text>
  15. <u-icon name="arrow-leftward" color="#f56c6c" size="12"></u-icon>
  16. </view>
  17. </view>
  18. </u-scroll-list>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. list: [{
  25. price: '230.5',
  26. thumb: 'https://cdn.uviewui.com/uview/goods/1.jpg'
  27. }, {
  28. price: '74.1',
  29. thumb: 'https://cdn.uviewui.com/uview/goods/2.jpg'
  30. }, {
  31. price: '8457',
  32. thumb: 'https://cdn.uviewui.com/uview/goods/6.jpg'
  33. }, {
  34. price: '1442',
  35. thumb: 'https://cdn.uviewui.com/uview/goods/5.jpg'
  36. }, {
  37. price: '541',
  38. thumb: 'https://cdn.uviewui.com/uview/goods/2.jpg'
  39. }, {
  40. price: '234',
  41. thumb: 'https://cdn.uviewui.com/uview/goods/3.jpg'
  42. }, {
  43. price: '562',
  44. thumb: 'https://cdn.uviewui.com/uview/goods/4.jpg'
  45. }, {
  46. price: '251.5',
  47. thumb: 'https://cdn.uviewui.com/uview/goods/1.jpg'
  48. }]
  49. }
  50. },
  51. methods: {
  52. left() {
  53. console.log('left');
  54. },
  55. right() {
  56. console.log('right');
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="scss">
  62. .scroll-list {
  63. @include flex(column);
  64. &__goods-item {
  65. margin-right: 20px;
  66. &__image {
  67. width: 60px;
  68. height: 60px;
  69. border-radius: 4px;
  70. }
  71. &__text {
  72. color: #f56c6c;
  73. text-align: center;
  74. font-size: 12px;
  75. margin-top: 5px;
  76. }
  77. }
  78. &__show-more {
  79. background-color: #fff0f0;
  80. border-radius: 3px;
  81. padding: 3px 6px;
  82. @include flex(column);
  83. align-items: center;
  84. &__text {
  85. font-size: 12px;
  86. width: 12px;
  87. color: #f56c6c;
  88. line-height: 16px;
  89. }
  90. }
  91. }
  92. </style>
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/228890
推荐阅读
相关标签
  

闽ICP备14008679号