demo.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="demo">
  3. <h2>{{ translate('basic') }}</h2>
  4. <nut-cell>
  5. <nut-list :listData="count" @scroll-bottom="handleScroll">
  6. <template v-slot="{ item, index }">
  7. <div class="list-item">
  8. {{ index }}
  9. </div>
  10. </template>
  11. </nut-list>
  12. </nut-cell>
  13. </div>
  14. </template>
  15. <script lang="ts">
  16. import { onMounted, reactive, toRefs } from 'vue';
  17. import { createComponent } from '@/packages/utils/create';
  18. const { createDemo, translate } = createComponent('list');
  19. import { useTranslate } from '@/sites/assets/util/useTranslate';
  20. const initTranslate = () =>
  21. useTranslate({
  22. 'zh-CN': {
  23. basic: '基本用法'
  24. },
  25. 'en-US': {
  26. basic: 'Basic Usage'
  27. }
  28. });
  29. export default createDemo({
  30. props: {},
  31. setup() {
  32. initTranslate();
  33. const state = reactive({
  34. count: new Array(100).fill(0)
  35. });
  36. const handleScroll = () => {
  37. let arr = new Array(100).fill(0);
  38. const len = state.count.length;
  39. state.count = state.count.concat(arr.map((item: number, index: number) => len + index + 1));
  40. };
  41. onMounted(() => {
  42. state.count = state.count.map((item: number, index: number) => index + 1);
  43. });
  44. return { ...toRefs(state), handleScroll, translate };
  45. }
  46. });
  47. </script>
  48. <style lang="scss">
  49. .demo {
  50. .nut-cell {
  51. height: 100%;
  52. }
  53. .nut-list-item {
  54. display: flex;
  55. align-items: center;
  56. justify-content: center;
  57. width: 100%;
  58. margin-bottom: 10px;
  59. height: 50px;
  60. background-color: #f4a8b6;
  61. border-radius: 10px;
  62. }
  63. }
  64. </style>