customizable.vue 3.1 KB

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