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

vue ElementUI實(shí)現(xiàn)異步加載樹

 更新時(shí)間:2021年06月06日 13:06:59   作者:陳岐祥  
這篇文章主要為大家詳細(xì)介紹了vue ElementUI實(shí)現(xiàn)異步加載樹,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue ElementUI實(shí)現(xiàn)異步加載樹的具體代碼,供大家參考,具體內(nèi)容如下

路由文件修改

import List from '@/components/list.vue'
import Add from '@/components/add.vue'
import Tree from '@/components/tree.vue'
import AsynTree from '@/components/asyntree.vue'

export default{
    routes:[
        {path:"/list",component:List},
        {path:"/add",component:Add},
        {path:"/add/:id",component:Add},
        {path:"/tree",component:Tree},
        {path:"/asyntree",component:AsynTree}
    ]

}

首頁app.vue

<template>
  <div id="app">
    <router-link to="/add">添加</router-link>&nbsp;&nbsp;
    <router-link to="/list">列表</router-link>&nbsp;&nbsp;
    <router-link to="/tree">樹結(jié)構(gòu)</router-link>&nbsp;&nbsp;
    <router-link to="/asyntree">異步樹結(jié)構(gòu)</router-link>&nbsp;&nbsp;
    <router-view></router-view>
  </div>
</template>

<script>
import List from './components/list.vue'

export default {
  name: 'app',
  components: {
    List
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

異步加載樹頁面

<template>


<el-container>
  <el-aside width="200px">
    <el-tree ref="tree"
    :data="data"
    lazy
    show-checkbox
    node-key="id"
    check-strictly
    :load="loadnode"
    :props="defaultProps"
    @node-click="nodeclick">
    </el-tree>
  </el-aside>
  <el-main>

    <el-form :model="typeinfo" class="demo-form-inline">
    <el-form-item label="ID">
        <el-input v-model="typeinfo.id" readonly></el-input>
    </el-form-item>
    <el-form-item label="分類名稱">
        <el-input v-model="typeinfo.label" placeholder="分類名稱"></el-input>
    </el-form-item>
    <el-form-item label="序號(hào)">
        <el-input v-model="typeinfo.seqno" placeholder="序號(hào)"></el-input>
    </el-form-item>
   <el-form-item label="父ID">
        <el-input v-model="typeinfo.pid" readonly></el-input>
    </el-form-item>
    <el-form-item>
        <el-button type="primary" @click="dosave">保存</el-button>
        <el-button type="primary" @click="dochildsave">添加節(jié)點(diǎn)</el-button>
    </el-form-item>
    </el-form>

  </el-main>
</el-container>

</template>

<script>
import axios from 'axios'

export default {
    data() {
        return {
            data:[],//樹對(duì)象數(shù)據(jù)模型
            defaultProps: {//樹對(duì)象屬性對(duì)應(yīng)關(guān)系
                children: 'children',
                label: 'label'
            },
            typeinfo: {//商品分類實(shí)體對(duì)象
                id:'',
                pid:'',
                label: '',
                seqno: ''
            }
        }
    },
    methods: {
        loadnode(node,resolve){
            //如果展開第一級(jí)節(jié)點(diǎn),從后臺(tái)加載一級(jí)節(jié)點(diǎn)列表
            if(node.level==0)
            {
                this.loadfirstnode(resolve);
            }
            //如果展開其他級(jí)節(jié)點(diǎn),動(dòng)態(tài)從后臺(tái)加載下一級(jí)節(jié)點(diǎn)列表
            if(node.level>=1)
            {
                this.loadchildnode(node,resolve);
            }
        },
        //加載第一級(jí)節(jié)點(diǎn)
        loadfirstnode(resolve){
            axios.get('http://localhost:6060/loadtype')
                .then(function(resp){
                    resolve(resp.data);
                })
        },
        //刷新樹組件
        refreshtree(){
            var _this = this;
            axios.get('http://localhost:6060/loadtype')
                .then(function(resp){
                    _this.data = resp.data;
                })
        },
        //加載節(jié)點(diǎn)的子節(jié)點(diǎn)集合
        loadchildnode(node,resolve){
            axios.get('http://localhost:6060/loadtypechild?pid='+node.data.id)
                .then(function(resp){
                    resolve(resp.data);
                })
        },
        //點(diǎn)擊節(jié)點(diǎn)上觸發(fā)的事件,傳遞三個(gè)參數(shù),數(shù)據(jù)對(duì)象使用第一個(gè)參數(shù)
        nodeclick(data,dataObj,self)
        {
            //alert(data.label+",id="+data.id);
            this.typeinfo.id=data.id;
            this.typeinfo.pid=data.pid;
            this.typeinfo.label=data.label;
            this.typeinfo.seqno=data.seqno;
        },
        //保存分類方法
        dosave()
        {
            var _this = this;
             axios.post('http://localhost:6060/savetype',this.typeinfo)
                .then(function(resp){
                    if(resp.data)
                        _this.refreshtree();
                })
        },
        //保存子分類方法
        dochildsave()
        {
            //判斷左側(cè)樹組件是否選擇了一個(gè)節(jié)點(diǎn)
            var cnt=this.$refs['tree'].getCheckedNodes().length;
            if(cnt!=1)
            {
                this.$message('必須選擇唯一父節(jié)點(diǎn)');
                return;
            }
            //通過this.$refs['tree']獲取樹對(duì)象,其中tree是樹組件的ref屬性
            var dataObj = this.$refs['tree'].getCheckedNodes()[0];
    
            this.typeinfo.id='';
            this.typeinfo.pid=dataObj.id;
            var _this = this;
            axios.post('http://localhost:6060/savetype',this.typeinfo)
                .then(function(resp){
                    if(resp.data)
                        _this.refreshtree();
                })
        }
    }

}
</script>

后臺(tái)Controller

@RequestMapping("/loadtype")
 @ResponseBody
 public List<TypeInfo> getTypeJson()
 {
  List<TypeInfo> rtn = getFirstNode();
  
  return rtn;
 }
  
 @RequestMapping("/loadtypechild")
 @ResponseBody
 public List<TypeInfo> getTypeByPid(Integer pid)
 {
  System.out.println("pid==="+pid);
  List<TypeInfo> rtn = addsrv.getTypeList(pid);
  
  return rtn;
 }
 
 private List<TypeInfo> getFirstNode()
 {
  TypeInfo root = addsrv.getRootType();
  List<TypeInfo> firstList = addsrv.getTypeList(root.getId());
  for(TypeInfo ti:firstList)
   recurseNode(ti);
  return firstList;
 }
 
 private void recurseNode(TypeInfo ti)
 {
  List<TypeInfo> children = addsrv.getTypeList(ti.getId());
  System.out.println("ti.id"+ti.getId()+",children="+children);
  if(children==null || children.size()==0)
   return;
  ti.setChildren(children);
  for(TypeInfo chd:children)
  {
   recurseNode(chd);
  }
 }
 
 @RequestMapping("/savetype")
 @ResponseBody
 public Boolean savetype(@RequestBody TypeInfo ti)
 {
  try {
   Integer id = ti.getId();
   if(id != null)
    addsrv.updateType(ti);
   else {
    addsrv.saveType(ti);
   }
   return true;
  } catch (Exception e) {
   return false;
  }
  
 }

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue中的Ajax?配置代理slot插槽的方法詳解

    Vue中的Ajax?配置代理slot插槽的方法詳解

    這篇文章主要介紹了Vue中的Ajax?配置代理?slot插槽的相關(guān)知識(shí),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-06-06
  • vue遞歸實(shí)現(xiàn)自定義tree組件

    vue遞歸實(shí)現(xiàn)自定義tree組件

    這篇文章主要為大家詳細(xì)介紹了vue遞歸實(shí)現(xiàn)自定義tree組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • 前端MVVM框架解析之雙向綁定

    前端MVVM框架解析之雙向綁定

    這篇文章主要介紹了MVVM 框架解析之雙向綁定,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • vuex新手進(jìn)階篇之改變state?mutations的使用

    vuex新手進(jìn)階篇之改變state?mutations的使用

    在vue的項(xiàng)目中不可避免的會(huì)使用到vuex用于數(shù)據(jù)的存儲(chǔ),下面這篇文章主要給大家介紹了關(guān)于vuex新手進(jìn)階篇之改變state?mutations的使用,文中通過圖文以及實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • Vue2源碼解析之自定義指令

    Vue2源碼解析之自定義指令

    自定義指令,其實(shí)就是在vue提供的鉤子中寫代碼,這篇文章將從源碼的角度,帶大家深入了解一下Vue2種自定義指令的實(shí)現(xiàn)與使用,需要的可以參考一下
    2023-05-05
  • Vue實(shí)現(xiàn)雙向滑動(dòng)輸入條

    Vue實(shí)現(xiàn)雙向滑動(dòng)輸入條

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)雙向滑動(dòng)輸入條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • vuex中的 mapState,mapGetters,mapActions,mapMutations 的使用

    vuex中的 mapState,mapGetters,mapActions,mapMutations 的使用

    在vuex中有四大金剛分別是State, Mutations,Actions,Getters,本文對(duì)這四大金剛做了詳細(xì)介紹,本文重點(diǎn)是給大家介紹vuex中的 mapState,mapGetters,mapActions,mapMutations 的使用,感興趣的朋友一起看看吧
    2018-04-04
  • vue-resourse將json數(shù)據(jù)輸出實(shí)例

    vue-resourse將json數(shù)據(jù)輸出實(shí)例

    這篇文章主要為大家詳細(xì)介紹了vue-resourse將json數(shù)據(jù)輸出實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • 解決vue+element 鍵盤回車事件導(dǎo)致頁面刷新的問題

    解決vue+element 鍵盤回車事件導(dǎo)致頁面刷新的問題

    今天小編就為大家分享一篇解決vue+element 鍵盤回車事件導(dǎo)致頁面刷新的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • vue如何監(jiān)聽el-select選擇值的變化

    vue如何監(jiān)聽el-select選擇值的變化

    這篇文章主要介紹了vue如何監(jiān)聽el-select選擇值的變化,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04

最新評(píng)論

明溪县| 沧州市| 高阳县| 江陵县| 荥阳市| 红河县| 衡阳县| 溧阳市| 尉犁县| 临高县| 延吉市| 策勒县| 峡江县| 台南市| 郯城县| 富顺县| 专栏| 景德镇市| 西乌| 抚松县| 武鸣县| 达日县| 宿州市| 开封县| 湘乡市| 凤凰县| 龙州县| 筠连县| 娄底市| 新宁县| 沅江市| 长沙市| 江门市| 盘山县| 伊通| 石阡县| 永川市| 莱阳市| 长春市| 德令哈市| 河源市|