demo.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <div class="demo-list">
  3. <nut-noticebar
  4. :closeMode="true"
  5. v-if="!isMobile"
  6. >此 Demo 在 PC 端浏览器与移动端浏览器体验差异较大,建议在 Android 或 iOS 设备上体验。</nut-noticebar>
  7. <h4>横向滑动</h4>
  8. <p>支持惯性和吸边回弹,支持滑动到底跳转链接。</p>
  9. <p>
  10. <nut-button type="light" shape="circle" size="small" @click="scrollToPosHor()">返回第一个</nut-button>
  11. </p>
  12. <div class="hor-panel">
  13. <nut-scroller @jump="jump()" @scrollToCbk="scrollToCbkHor" :scrollTo="scrollToHor">
  14. <div slot="list" class="nut-hor-list-item" v-for="(item, index) of listData" :key="index">
  15. <dl class="nut-scroller-item-info">
  16. <dt>防水升级版 蓝 迷你小音</dt>
  17. <dd>2018-02-25</dd>
  18. </dl>
  19. </div>
  20. <slot slot="more">
  21. <div class="nut-hor-jump-more">查看更多</div>
  22. </slot>
  23. </nut-scroller>
  24. </div>
  25. <h4>横向小于一屏</h4>
  26. <div class="hor-panel">
  27. <nut-scroller @jump="jump()">
  28. <div slot="list" class="nut-hor-list-item" v-for="(item, index) of listData3" :key="index">
  29. <dl class="nut-scroller-item-info">
  30. <dt>防水升级版 蓝牙音箱 小音</dt>
  31. <dd>2018-02-25</dd>
  32. </dl>
  33. </div>
  34. </nut-scroller>
  35. </div>
  36. <h4>纵向滑动</h4>
  37. <p>支持下拉刷新、上拉加载更多。</p>
  38. <p>
  39. <nut-button type="light" shape="circle" size="small" @click="scrollToPos()">返回列表顶部</nut-button>
  40. </p>
  41. <div class="vert-panel">
  42. <nut-scroller
  43. :is-un-more="isUnMore1"
  44. :is-loading="isLoading1"
  45. :type="'vertical'"
  46. :propsTime="0"
  47. :scrollTo="scrollTo"
  48. @loadMore="loadMoreVert"
  49. @pulldown="pulldown"
  50. @scrollToCbk="scrollToCbk"
  51. @scrollChange="scrollChange"
  52. >
  53. <div slot="list" class="nut-vert-list-panel">
  54. <div class="nut-vert-list-item" v-for="(item, index) of listData1" :key="index">
  55. <dl class="nut-scroller-item-info">
  56. <dt>{{ index }}防水升级版 蓝牙音箱 低音炮 IPX7设计 户外便携音响 迷你小音</dt>
  57. <dd>2018-02-25</dd>
  58. </dl>
  59. </div>
  60. </div>
  61. </nut-scroller>
  62. </div>
  63. <h4>纵向不满一屏</h4>
  64. <p>支持下拉刷新、上拉加载更多。</p>
  65. <div class="vert-panel">
  66. <nut-scroller
  67. :is-un-more="isUnMore2"
  68. :is-loading="isLoading2"
  69. :type="'vertical'"
  70. @loadMore="loadMoreVert2"
  71. @pulldown="pulldown2"
  72. >
  73. <div slot="list" class="nut-vert-list-panel">
  74. <div class="nut-vert-list-item" v-for="(item, index) of listData2" :key="index">
  75. <dl class="nut-scroller-item-info">
  76. <dt>{{ index }}防水升级版 蓝牙音箱 低音炮 IPX7设计 户外便携音响 迷你小音</dt>
  77. <dd>2018-02-25</dd>
  78. </dl>
  79. </div>
  80. </div>
  81. </nut-scroller>
  82. </div>
  83. </div>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. return {
  89. listData: new Array(20),
  90. listData1: new Array(20),
  91. listData2: [1, 2],
  92. listData3: [1],
  93. maxPages: 4,
  94. isUnMore1: false,
  95. isLoading1: false,
  96. page1: 2,
  97. maxPages2: 1,
  98. isUnMore2: false,
  99. isLoading2: false,
  100. page2: 2,
  101. timers: null,
  102. scrollTo: 1,
  103. scrollToHor: 1
  104. };
  105. },
  106. methods: {
  107. jump() {
  108. location.href = 'http://www.jd.com';
  109. },
  110. scrollToCbk() {
  111. this.scrollTo = 1;
  112. },
  113. scrollToCbkHor() {
  114. this.scrollToHor = 1;
  115. },
  116. scrollToPosHor() {
  117. this.scrollToHor = 0;
  118. },
  119. scrollChange(event) {
  120. console.log(event);
  121. },
  122. scrollToPos() {
  123. this.scrollTo = 0;
  124. },
  125. loadMoreVert() {
  126. this.isLoading1 = true;
  127. if (this.page1 > this.maxPages) {
  128. this.isUnMore1 = true;
  129. this.isLoading1 = false;
  130. } else {
  131. clearTimeout(this.timers);
  132. this.timer = setTimeout(() => {
  133. this.isLoading1 = false;
  134. this.isUnMore1 = false;
  135. this.listData1 = new Array(20 * this.page1);
  136. this.page1 = ++this.page1;
  137. }, 300);
  138. }
  139. },
  140. pulldown() {
  141. this.isLoading1 = true;
  142. clearTimeout(this.timers);
  143. this.timer = setTimeout(() => {
  144. this.isLoading1 = false;
  145. this.isUnMore1 = false;
  146. this.listData1 = new Array(20);
  147. this.page1 = 2;
  148. }, 3000);
  149. },
  150. loadMoreVert2() {
  151. this.isLoading2 = true;
  152. if (this.page2 > this.maxPages2) {
  153. this.isUnMore2 = true;
  154. this.isLoading2 = false;
  155. } else {
  156. clearTimeout(this.timers);
  157. this.timer = setTimeout(() => {
  158. this.isLoading2 = false;
  159. this.isUnMore2 = false;
  160. this.listData2 = new Array(20 * this.page2);
  161. this.page2 = ++this.page1;
  162. }, 300);
  163. }
  164. },
  165. pulldown2() {
  166. this.isLoading2 = true;
  167. clearTimeout(this.timers);
  168. this.timer = setTimeout(() => {
  169. this.isLoading2 = false;
  170. this.isUnMore2 = false;
  171. this.listData2 = new Array(10);
  172. this.page2 = 2;
  173. }, 300);
  174. }
  175. },
  176. destroyed() {
  177. clearTimeout(this.timer);
  178. }
  179. };
  180. </script>
  181. <style lang="scss" scoped>
  182. .hor-panel {
  183. height: 80px;
  184. background-color: #e0e0e0;
  185. display: flex;
  186. }
  187. .nut-hor-list {
  188. .nut-hor-list-item {
  189. display: flex;
  190. align-content: center;
  191. justify-content: center;
  192. flex-shrink: 0;
  193. width: 180px;
  194. height: 60px;
  195. padding: 10px;
  196. margin-left: 10px;
  197. background-color: #fff;
  198. color: #000;
  199. line-height: 100px;
  200. }
  201. }
  202. .nut-hor-jump-more {
  203. display: flex;
  204. align-items: center;
  205. height: 100%;
  206. width: 20px;
  207. padding: 0 5px;
  208. margin-left: 10px;
  209. font-size: 12px;
  210. text-align: center;
  211. color: $primary-color;
  212. background-color: #fff;
  213. }
  214. .nut-scroller-item-img {
  215. height: 58px;
  216. width: 58px;
  217. border-radius: 10px;
  218. border: 1px solid #eee;
  219. overflow: hidden;
  220. }
  221. dl,
  222. dt,
  223. dd {
  224. margin: 0;
  225. }
  226. .nut-scroller-item-info {
  227. flex: 1;
  228. padding-left: 10px;
  229. line-height: 20px;
  230. dt {
  231. font-size: 14px;
  232. }
  233. dd {
  234. margin-left: 0;
  235. font-size: 12px;
  236. }
  237. }
  238. .vert-panel {
  239. height: 400px;
  240. padding: 10px;
  241. background-color: #e1e1e1;
  242. }
  243. .nut-vert-list-panel {
  244. .nut-vert-list-item {
  245. display: flex;
  246. height: 60px;
  247. padding: 10px;
  248. margin-bottom: 10px;
  249. //background-color: mix($primary-color, #FFF, 90%);
  250. background-color: #fff;
  251. color: #000;
  252. }
  253. }
  254. </style>