index.vue 965 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <div>
  3. <el-tree
  4. :data="treeData"
  5. ref="tree"
  6. node-key="id"
  7. :highlight-current="true"
  8. :default-expanded-keys="[1]"
  9. :current-node-key="currentNodekey"
  10. :props="defaultProps"
  11. @node-click="handleNodeClick"
  12. ></el-tree>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'dataReportLeft',
  18. props: {
  19. treeData: {
  20. type: Array,
  21. default: () => []
  22. }
  23. },
  24. data() {
  25. return {
  26. defaultProps:{
  27. children: 'children',
  28. label: 'cusareaName'
  29. },
  30. currentNodekey: ''
  31. };
  32. },
  33. watch: {
  34. treeData: {
  35. handler(res) {
  36. this.currentNodekey = res[0].id;
  37. this.$nextTick(() => {
  38. this.$refs.tree.setCurrentKey(this.currentNodekey);
  39. });
  40. },
  41. deep: true
  42. }
  43. },
  44. methods: {
  45. handleNodeClick(data) {
  46. this.$emit("setCurrentData",data?.cusareaId,data)
  47. }
  48. }
  49. };
  50. </script>
  51. <style lang="sass" scoped>
  52. </style>