TreeTable.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div>
  3. <el-table
  4. :data="tableData"
  5. style="width: 100%"
  6. row-key="id"
  7. stripe
  8. border
  9. lazy
  10. :load="load"
  11. :tree-props="{children: childrenName, hasChildren: hasChildrenName}">
  12. <el-table-column :prop="item.key" :label="item.name" v-for="(item,index) in title">
  13. </el-table-column>
  14. </el-table>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. tableData: [
  22. ]
  23. }
  24. },
  25. props:['title','sendUrl','childrenName','hasChildrenName'],
  26. mounted() {
  27. let ret=this.getDataList({'p_id':0});
  28. this.tableData=ret;
  29. },
  30. methods: {
  31. startSend(sendData){
  32. let ret=this.getDataList(sendData);
  33. this.tableData=ret;
  34. },
  35. load(tree, treeNode, resolve) {
  36. let ret=this.getDataList({'p_id':tree.id});
  37. resolve(ret)
  38. },
  39. getDataList(sendData) {
  40. var cmObjStr = eval("(" + $.ajax({
  41. url: this.sendUrl,
  42. async: false,//关键是这个参数 是否异步请求=>false:使用同步请求
  43. type: "POST",
  44. data: sendData
  45. }).responseText + ")");
  46. if(cmObjStr.code*1==1){
  47. return cmObjStr.data;
  48. }else {
  49. return [];
  50. }
  51. }
  52. },
  53. }
  54. </script>