Tree.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <div class="custom-tree-container">
  3. <div class="block">
  4. <el-tree
  5. :data="data"
  6. show-checkbox
  7. default-expand-all
  8. node-key="id"
  9. @check-change="getCheckedKeys"
  10. ref="tree"
  11. highlight-current
  12. :default-checked-keys="select_keys"
  13. :props="defaultProps">
  14. </el-tree>
  15. </div>
  16. </div>
  17. </template>
  18. <style scoped>
  19. .custom-tree-node {
  20. flex: 1;
  21. display: flex;
  22. align-items: center;
  23. justify-content: space-between;
  24. font-size: 14px;
  25. padding-right: 8px;
  26. }
  27. </style>
  28. <script>
  29. export default {
  30. methods: {
  31. getCheckedKeys() {
  32. var keys=this.$refs.tree.getCheckedKeys();
  33. console.log('子组件获取到数据------');
  34. console.log(keys);
  35. console.log('开始传递------');
  36. this.$emit('set-keys',keys);
  37. },
  38. },
  39. props: ['list','select_ids'],
  40. data() {
  41. console.log(this._props.list);
  42. console.log(this._props.select_ids);
  43. return {
  44. data: this._props.list ? this._props.list : [],
  45. select_keys: this._props.select_ids ? this._props.select_ids : [],
  46. defaultProps: {
  47. children: 'children',
  48. label: 'label'
  49. }
  50. };
  51. }
  52. };
  53. </script>