我用Vue.js与ElementUI搭建了一个无限级联层级表格组件

 前言

今天,回老家了。第一件事就是回家把大屏安排上,写作的感觉太爽了,终于可以专心地写文章了。我们今天要做的项目是怎么样搭建一个无限级联层级表格组件,好了,多了不多说,赶快行动起来吧!

项目一览

到底是啥样子来?我们来看下。

正如你所看到的那样,这个组件涉及添加、删除、编辑功能,并且可以无限级嵌套。那么怎样实现的?我们来看下。

源码

直接给出源码,就是这么直接。

 
 
 
 
  1.             
  2.         
  3.         
  4.             :title="textMap[dialogStatus]"
  5.             :visible.sync="dialogFormVisible"
  6.             width="30%"
  7.         >
  8.             
  9.                 ref="dataForm"
  10.                 :rules="rules"
  11.                 :model="temp"
  12.                 label-position="left"
  13.                 label-width="120px"
  14.                 style="margin-left: 50px"
  15.             >
  16.                 
  17.                     label="层级:"
  18.                     prop="location"
  19.                     v-if="dialogStatus !== 'update'"
  20.                 >
  21.                     
  22.                         v-model="temp.location"
  23.                         placeholder="请选择层级"
  24.                         @change="locationChange"
  25.                         size="small"
  26.                     >
  27.                         
  28.                             v-for="item in locationData"
  29.                             :key="item.id"
  30.                             :label="item.name"
  31.                             :value="item.id"
  32.                         />
  33.                     
  34.                 
  35.                 
  36.                     v-if="sonStatus && dialogStatus !== 'update'"
  37.                     label="子位置:"
  38.                     prop="children"
  39.                 >
  40.                     
  41.                         size="small"
  42.                         :key="isResouceShow"
  43.                         v-model="temp.children"
  44.                         placeholder="请选择子位置"
  45.                         :label="'label'"
  46.                         :value="'value'"
  47.                         :options="tableData"
  48.                         :props="{ checkStrictly: true }"
  49.                         clearable
  50.                         @change="getCasVal"
  51.                     >
  52.                 
  53.                 
  54.                     
  55.                         v-model="temp.label"
  56.                         size="small"
  57.                         autocomplete="off"
  58.                         placeholder="请输入标签名称"
  59.                     >
  60.                 
  61.             
  62.             
  63.                 
  64.                     取消
  65.                 
  66.                 
  67.                     type="primary"
  68.                     size="small"
  69.                     @click="
  70.                         dialogStatus === 'create' ? createData() : updateData()
  71.                     "
  72.                 >
  73.                     确认
  74.                 
  75.             
  •         
  •