最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue?elementUI實現(xiàn)樹形結(jié)構(gòu)表格與懶加載

 更新時間:2022年01月04日 09:49:59   作者:別團(tuán)等shy哥發(fā)育  
這篇文章主要介紹了通過Vue和elementUI實現(xiàn)樹形結(jié)構(gòu)表格與懶加載,文中的示例代碼講解詳細(xì),感興趣的小伙伴快來跟隨小編一起學(xué)習(xí)一下吧

1、實現(xiàn)效果

2、后端實現(xiàn)

2.1 實體類

@Data
@ApiModel(description = "數(shù)據(jù)字典")
@TableName("dict")
public class Dict {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    private Long id;

    @ApiModelProperty(value = "創(chuàng)建時間")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private Date createTime;

    @ApiModelProperty(value = "更新時間")
    @TableField("update_time")
    private Date updateTime;

    @ApiModelProperty(value = "邏輯刪除(1:已刪除,0:未刪除)")
    @TableLogic
    @TableField("is_deleted")
    private Integer isDeleted;

    @ApiModelProperty(value = "其他參數(shù)")
    @TableField(exist = false)
    private Map<String,Object> param = new HashMap<>();

    @ApiModelProperty(value = "上級id")
    @TableField("parent_id")
    private Long parentId;

    @ApiModelProperty(value = "名稱")
    @TableField("name")
    private String name;

    @ApiModelProperty(value = "值")
    @TableField("value")
    private String value;

    @ApiModelProperty(value = "編碼")
    @TableField("dict_code")
    private String dictCode;

    @ApiModelProperty(value = "是否包含子節(jié)點")
    @TableField(exist = false)
    private boolean hasChildren;

}

上面必須包含一個hasChildren屬性,即使數(shù)據(jù)庫中沒有該屬性,這是element框架要求的。

2.2 數(shù)據(jù)庫中的數(shù)據(jù)結(jié)構(gòu)

2.3 后端接口

如果完全用后端實現(xiàn)的話,那寫個遞歸把所有數(shù)據(jù)按照層次結(jié)構(gòu)查詢完并封裝好即可。但element的table組件給我們封裝好了一些東西,我們只需要在這里根據(jù)上級id查詢子數(shù)據(jù)列表即可。

controller代碼:

 //根據(jù)上級id查詢子數(shù)據(jù)列表
    @ApiOperation(value = "根據(jù)上級id查詢子數(shù)據(jù)列表")
    @GetMapping("findChildData/{id}")
    public Result findChildData(@PathVariable Long id){
        List<Dict> list = dictService.findChildData(id);
        return Result.ok(list);
    }

service

service實現(xiàn)類

@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictService {

    //根據(jù)上級id查詢子數(shù)據(jù)列表
    @Override
    public List<Dict> findChildData(Long id) {
        QueryWrapper<Dict> wrapper=new QueryWrapper<>();
        wrapper.eq("parent_id",id);
        List<Dict> list = baseMapper.selectList(wrapper);
        //向list集合中的每個dict對象中設(shè)置hasChildren
        list.forEach(x->{
            Long dictId = x.getId();
            boolean isChild = this.isChildren(dictId);
            x.setHasChildren(isChild);
        });
        return list;
    }

    //判斷id下面是否有子數(shù)據(jù)
    private boolean isChildren(Long id){
        QueryWrapper<Dict> wrapper=new QueryWrapper<>();
        wrapper.eq("parent_id",id);
        Integer count = baseMapper.selectCount(wrapper);
        return count > 0;
    }
}

2.4 swagger測試后端結(jié)構(gòu)功能是否正常

3、前端實現(xiàn)

3.1 頁面中引入el-table組件

list.vue

<template>
  <div class="app-container">

    <el-table
      :data="list"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :load="getChildrens"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column label="名稱" width="230" align="left">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="編碼" width="220">
        <template slot-scope="{row}">
          {{ row.dictCode }}
        </template>
      </el-table-column>
      <el-table-column label="值" width="230" align="left">
        <template slot-scope="scope">
          <span>{{ scope.row.value }}</span>
        </template>
      </el-table-column>
      <el-table-column label="創(chuàng)建時間" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
import dict from '@/api/dict'
export default {
  name: 'list',
  data(){
    return{
      list:[], //數(shù)據(jù)字典列表數(shù)組
      dialogImportVisible:false,  //設(shè)置彈框是否彈出
    }
  },
  created() {
    this.getDictList(1)
  },
  methods:{
    //數(shù)據(jù)字典列表
    getDictList(id){
      dict.dictList(id)
        .then(response=>{
            this.list=response.data
        })
    },
    getChildrens(tree, treeNode, resolve) {
      dict.dictList(tree.id).then(response => {
        resolve(response.data)
      })
    },
  }
}
</script>

<style scoped>

</style>

上面關(guān)鍵的方法是getChildrens這個方法,在每一層調(diào)用后端接口將子節(jié)點數(shù)據(jù)查詢出來,并加入樹形結(jié)構(gòu)的表格數(shù)據(jù)中。

調(diào)用后端結(jié)構(gòu)的工具js文件 dict.js

import request from '@/utils/request'

export default {
  //數(shù)據(jù)字典列表
  dictList(id){
    return request({
      url: `/admin/cmn/dict/findChildData/${id}`,
      method: 'get'
    })
  },
}

3.2 實現(xiàn)效果

前后端測試都沒有問題,由于使用的是懶加載,只有去點擊父節(jié)點的時候,子節(jié)點的數(shù)據(jù)才會被加載,避免因數(shù)據(jù)量太大導(dǎo)致系統(tǒng)卡頓。

到此這篇關(guān)于Vue elementUI實現(xiàn)樹形結(jié)構(gòu)表格與懶加載的文章就介紹到這了,更多相關(guān)Vue elementUI內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue?2?如何添加?register-service-worker?實現(xiàn)緩存請求的問題

    Vue?2?如何添加?register-service-worker?實現(xiàn)緩存請求的問題

    這篇文章主要介紹了Vue?2?如何添加?register-service-worker?以實現(xiàn)緩存請求的目的,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-11-11
  • Vite版本更新檢查實現(xiàn)頁面自動刷新的解決思路

    Vite版本更新檢查實現(xiàn)頁面自動刷新的解決思路

    這篇文章主要給大家介紹了關(guān)于Vite版本更新檢查實現(xiàn)頁面自動刷新的解決思路,文中通過實例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2023-02-02
  • Vue+Node實現(xiàn)大文件上傳和斷點續(xù)傳

    Vue+Node實現(xiàn)大文件上傳和斷點續(xù)傳

    文件上傳在很多項目中都用的到,如果是幾M的很快就傳送完畢,如果是大文件呢?本文將利用Vue+Node實現(xiàn)大文件上傳和斷點續(xù)傳,感興趣的可以了解一下
    2022-04-04
  • vue prop傳值類型檢驗方式

    vue prop傳值類型檢驗方式

    這篇文章主要介紹了vue prop傳值類型檢驗方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Vue如何實現(xiàn)分頁功能代碼實例

    Vue如何實現(xiàn)分頁功能代碼實例

    這篇文章主要給大家介紹了關(guān)于Vue如何實現(xiàn)分頁功能的相關(guān)資料,Vue分頁功能的實現(xiàn)需要前端和后端共同配合完成,文中通過代碼實例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-09-09
  • vue-cli創(chuàng)建vue項目的詳細(xì)步驟記錄

    vue-cli創(chuàng)建vue項目的詳細(xì)步驟記錄

    vue.cli是vue中的項目構(gòu)造工具,是一個npm包,需要安裝node.js和 git才能用,下面這篇文章主要給大家介紹了關(guān)于利用vue-cli創(chuàng)建vue項目的詳細(xì)步驟,需要的朋友可以參考下
    2022-06-06
  • vue router自動判斷左右翻頁轉(zhuǎn)場動畫效果

    vue router自動判斷左右翻頁轉(zhuǎn)場動畫效果

    最近公司項目比較少終于有空來記錄一下自己對vue-router的一些小小的使用心得,本文給大家分享vue router自動判斷左右翻頁轉(zhuǎn)場動畫效果,感興趣的朋友一起看看吧
    2017-10-10
  • vue 獲取元素額外生成的data-v-xxx操作

    vue 獲取元素額外生成的data-v-xxx操作

    這篇文章主要介紹了vue 獲取元素額外生成的data-v-xxx操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 微信小程序Webview與H5通信的思路與實戰(zhàn)記錄

    微信小程序Webview與H5通信的思路與實戰(zhàn)記錄

    這篇文章主要介紹了微信小程序Webview與H5通信的思路與實戰(zhàn)的相關(guān)資料,由于微信小程序與H5之間的通信限制,無法滿足業(yè)務(wù)需求,通過動態(tài)改變url的hash值來傳遞參數(shù),并利用vue-router組件的路由守衛(wèi)來避免頁面刷新,需要的朋友可以參考下
    2025-01-01
  • Vue resource中的GET與POST請求的實例代碼

    Vue resource中的GET與POST請求的實例代碼

    本篇文章主要介紹了Vue resource中的GET與POST請求的實例代碼,非常具有實用價值,需要的朋友可以參考下
    2017-07-07

最新評論

马尔康县| 邢台县| 洪江市| 延寿县| 定结县| 改则县| 灵宝市| 临湘市| 瑞昌市| 穆棱市| 临清市| 浮山县| 福贡县| 博兴县| 什邡市| 太仆寺旗| 大石桥市| 城固县| 新绛县| 茌平县| 汉中市| 防城港市| 林甸县| 苍南县| 温泉县| 唐河县| 广东省| 乌什县| 江达县| 马边| 伊金霍洛旗| 平江县| 贵港市| 马尔康县| 那坡县| 达州市| 淅川县| 连城县| 双辽市| 观塘区| 江油市|