transfer.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <p style="text-align: center; margin: 0 0 20px">
  3. Customize data items using render-content
  4. </p>
  5. <div style="text-align: center">
  6. <el-transfer
  7. v-model="leftValue"
  8. style="text-align: left; display: inline-block"
  9. filterable
  10. :left-default-checked="[2, 3]"
  11. :right-default-checked="[1]"
  12. :render-content="renderFunc"
  13. :titles="['Source', 'Target']"
  14. :button-texts="['To left', 'To right']"
  15. :format="{
  16. noChecked: '${total}',
  17. hasChecked: '${checked}/${total}',
  18. }"
  19. :data="data"
  20. @change="handleChange"
  21. >
  22. <template #left-footer>
  23. <el-button class="transfer-footer" size="small">Operation</el-button>
  24. </template>
  25. <template #right-footer>
  26. <el-button class="transfer-footer" size="small">Operation</el-button>
  27. </template>
  28. </el-transfer>
  29. <p style="text-align: center; margin: 50px 0 20px">
  30. Customize data items using scoped slot
  31. </p>
  32. <div style="text-align: center">
  33. <el-transfer
  34. v-model="rightValue"
  35. style="text-align: left; display: inline-block"
  36. filterable
  37. :left-default-checked="[2, 3]"
  38. :right-default-checked="[1]"
  39. :titles="['Source', 'Target']"
  40. :button-texts="['To left', 'To right']"
  41. :format="{
  42. noChecked: '${total}',
  43. hasChecked: '${checked}/${total}',
  44. }"
  45. :data="data"
  46. @change="handleChange"
  47. >
  48. <template #default="{ option }">
  49. <span>{{ option.key }} - {{ option.label }}</span>
  50. </template>
  51. <template #left-footer>
  52. <el-button class="transfer-footer" size="small">Operation</el-button>
  53. </template>
  54. <template #right-footer>
  55. <el-button class="transfer-footer" size="small">Operation</el-button>
  56. </template>
  57. </el-transfer>
  58. </div>
  59. </div>
  60. </template>
  61. <script lang="ts" setup>
  62. import { ref } from 'vue'
  63. import type { VNode, VNodeProps } from 'vue'
  64. interface Option {
  65. key: number
  66. label: string
  67. disabled: boolean
  68. }
  69. const generateData = (): Option[] => {
  70. const data: Option[] = []
  71. for (let i = 1; i <= 15; i++) {
  72. data.push({
  73. key: i,
  74. label: `Option ${i}`,
  75. disabled: i % 4 === 0,
  76. })
  77. }
  78. return data
  79. }
  80. const data = ref(generateData())
  81. const rightValue = ref([1])
  82. const leftValue = ref([1])
  83. const renderFunc = (
  84. h: (type: string, props: VNodeProps | null, children?: string) => VNode,
  85. option: Option
  86. ) => {
  87. return h('span', null, option.label)
  88. }
  89. const handleChange = (
  90. value: number | string,
  91. direction: 'left' | 'right',
  92. movedKeys: string[] | number[]
  93. ) => {
  94. console.log(value, direction, movedKeys)
  95. }
  96. </script>
  97. <style>
  98. .transfer-footer {
  99. margin-left: 15px;
  100. padding: 6px 5px;
  101. }
  102. </style>