1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <template> <div> // 使用树形穿梭框组件 <tree-transfer :title="title" :from_data='fromData' :to_data='toData' :defaultProps="{label:'label'}" @add-btn='add' @remove-btn='remove' :mode='mode' height='540px' :filter="false" openAll> <template v-slot:from> <el-input v-model="ruleForm.name" placeholder="搜索"></el-input> </template>
<template v-slot:to> <el-input v-model="ruleForm.name" placeholder="搜索"></el-input> </template> </tree-transfer> </div> </template>
<script> import treeTransfer from 'el-tree-transfer' // 引入
export defult { components:{ treeTransfer } ,// 注册 data(){ return:{ mode: "transfer", // transfer addressList fromData:[ { id: "1", pid: 0, label: "一级 1", children: [ { id: "1-1", pid: "1", label: "二级 1-1", disabled: true, children: [] }, { id: "1-2", pid: "1", label: "二级 1-2", children: [ { id: "1-2-1", pid: "1-2", children: [], label: "二级 1-2-1" }, { id: "1-2-2", pid: "1-2", children: [], label: "二级 1-2-2" } ] } ] }, ], toData:[] } }, methods:{ // 切换模式 现有树形穿梭框模式transfer 和通讯录模式addressList changeMode() { if (this.mode == "transfer") { this.mode = "addressList"; } else { this.mode = "transfer"; } }, // 监听穿梭框组件添加 add(fromData,toData,obj){ // 树形穿梭框模式transfer时,返回参数为左侧树移动后数据、右侧树移动后数据、移动的{keys,nodes,halfKeys,halfNodes}对象 // 通讯录模式addressList时,返回参数为右侧收件人列表、右侧抄送人列表、右侧密送人列表 console.log("fromData:", fromData); console.log("toData:", toData); console.log("obj:", obj); }, // 监听穿梭框组件移除 remove(fromData,toData,obj){ // 树形穿梭框模式transfer时,返回参数为左侧树移动后数据、右侧树移动后数据、移动的{keys,nodes,halfKeys,halfNodes}对象 // 通讯录模式addressList时,返回参数为右侧收件人列表、右侧抄送人列表、右侧密送人列表 console.log("fromData:", fromData); console.log("toData:", toData); console.log("obj:", obj); } }, } </script>
|