当前位置:网站首页 > R语言数据分析 > 正文

element-ui的tree配合原生

一,实现效果
在这里插入图片描述

二,具体代码

<template> <div class="home"> <!-- <div class="title">使用koa2+vue+MySQL创建的一个demo</div> <ul class="contentBox"> <template v-for="(item, index) in list"> <li :key="index" class="item">{ 
   { 
    item.content }}</li> </template> </ul> --> <el-tree :data="data" node-key="id" @node-click="testClick" default-expand-all :expand-on-click-node="false" > <span class="custom-tree-node" slot-scope="{ node }"> <span>{ 
   { 
    node.label }}</span> <span> <el-button type="text" size="mini" class="mynum"> 数值 </el-button> </span> </span> </el-tree> <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" > <span>{ 
   { 
   name}}</span> <span>{ 
   { 
   age}}</span> <span slot="footer" class="dialog-footer"> <el-button @click="dialogVisible = false">取 消</el-button> <el-button type="primary" @click="dialogVisible = false" >确 定</el-button > </span> </el-dialog> </div> </template> <script> let id = 1000; export default { 
    name: "Home", data() { 
    const data = [ { 
    id: 1, label: "一级", num: "10", children: [ { 
    id: 4, label: "二级", num: "10", children: [ { 
    id: 9, num: "9", label: "三级", list: [ { 
    name: "卢", age: 18 }, { 
    name: "雄", age: 19 }, { 
    name: "卢", age: 18 }, { 
    name: "雄", age: 19 }, { 
    name: "卢", age: 18 }, { 
    name: "雄", age: 19 } ] }, { 
    id: 10, num: "1", label: "三级", list: [ { 
    name: "卢", age: 18 }, { 
    name: "雄", age: 19 }, { 
    name: "卢", age: 18 }, { 
    name: "雄", age: 19 } ] } ] } ] } ]; return { 
    list: [], data: JSON.parse(JSON.stringify(data)), dialogVisible: false, age:'', name:'' }; }, components: { 
   }, created() { 
    // this.getList(); }, methods: { 
    // async getList() { 
    // const { data: res } = await this.$http.get("/api/test", { 
    // params: { 
    // id: 14 // } // }); // this.list = res.data; // }, // append(data) { 
    // const newChild = { id: id++, label: 'testtest', children: [] }; // if (!data.children) { 
    // this.$set(data, 'children', []); // } // data.children.push(newChild); // }, // renderContent(h, { node, data, store }) { 
    // return ( // <span class="custom-tree-node"> // <span>{node.label}</span> // <span class="mynum">{node.num}</span> // </span> // ); // }, testClick(a, b, c) { 
    console.log("点击节点", a, b, c); var divBox = c.$refs.node; // 有节点了只要切换显示与隐藏 if ( divBox.lastChild.className == "mybox" || divBox.lastChild.className == "mybox-none" ) { 
    if (divBox.lastChild.className == "mybox") { 
    divBox.lastChild.className = "mybox-none"; } else { 
    divBox.lastChild.className = "mybox"; } console.log("进入这里"); } else { 
    //没有就创建节点 let newDiv = document.createElement("div"); newDiv.classList.add("mybox"); for (let i = 0; i < a.list.length; i++) { 
    //这里用abc中传进来的数据,有多少人,则循环多少次 var span2 = document.createElement("span"); span2.classList.add("myspan"); //这里用对应的数据 span2.addEventListener("click", e => { 
    var ev = e || window.event; if (ev && ev.stopPropagation) { 
    //非IE浏览器 ev.stopPropagation(); } else { 
    //IE浏览器(IE11以下) ev.cancelBubble = true; } console.log("可以往事件中传递的参数", a.list[i].age); this.name=a.list[i].name this.age=a.list[i].age this.dialogVisible=true }); span2.innerHTML = a.list[i].name; newDiv.appendChild(span2); } divBox.appendChild(newDiv); } console.log("+++", c.$refs.node.lastChild.className); }, handleClose(done) { 
    this.$confirm('确认关闭?') .then(_ => { 
    done(); }) .catch(_ => { 
   }); } } }; </script> <style lang="less" scoped> .home { 
    width: 600px; margin: 100px auto; .title { 
    text-align: center; font-size: 30px; } ul, li { 
    list-style: none; padding: 0; margin: 0; } .contentBox { 
    border: 1px solid #; margin-top: 20px; .item { 
    margin: 10px 20px; background: pink; &:hover { 
    background-color: lightgreen; } } } } /deep/ .custom-tree-node { 
    display: flex; justify-content: space-between; width: 100%; .mynum { 
    display: block; background: red; } } /deep/.el-tree-node { 
    .mybox { 
    display: flex; justify-content: space-between; height: 40px; background: #c0c0c0; color: red; line-height: 40px; .myspan { 
    display: block; widows: 180px; } } .mybox-none { 
    display: none; } } </style> 
到此这篇element-ui的tree配合原生的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 微信小程序报错:Unhandled promise rejection TypeError: WebAssembly.instantiate(): Argument 0 must be a buffe2024-12-01 21:36:06
  • cheerio获取元素内文本,但不包括其子元素内的文本值的方法2024-12-01 21:36:06
  • http抓包实践--(二)--web网页抓包和fiddler修改包2024-12-01 21:36:06
  • Fiddler中常用的方法2024-12-01 21:36:06
  • http抓包实践--(四)-http压缩和url encode2024-12-01 21:36:06
  • 对于rpx的理解和使用2024-12-01 21:36:06
  • http抓包实践--(一)--fiddler和http(s)2024-12-01 21:36:06
  • nrm的安装与配置及问题修复2024-12-01 21:36:06
  • 控制台报错:Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`2024-12-01 21:36:06
  • 移动端transform: translate(-50%, 0)的兼容写法2024-12-01 21:36:06
  • 全屏图片