今天记录组件的代码和一个调用它的父组件的代码,接口接收数据直接传element直接能用的,也就是经过上一章函数处理过的数据以下是代码

父组件

<template>
<commonfiltertree :placeholder="placeholder"
:data="data"
:showCheckbox="showCheckbox"
@check='getcheckdata'
:title="title"
:showScreen="showScreen"
@click='getCurrentKey'
@checkkey='getCheckedKeys'
:defaultExpandAll="defaultExpandAll"
:default='defaults'></commonfiltertree>
</template>
<script>
import commonfiltertree from "@/components/newCommon/tree/filtertree.vue";
export default {
components: {
commonfiltertree
},
data() {
return {
placeholder: '输入信息,按回车搜索',
showCheckbox: true,
data: [{
id: 1,
label: '一级 1',
children: [{
id: 4,
label: '二级 1-1',
children: [{
id: 9,
label: '三级 1-1-1'
}, {
id: 10,
label: '三级 1-1-2'
}]
}]
}, {
id: 2,
label: '一级 2',
children: [{
id: 5,
label: '二级 2-1'
}, {
id: 6,
label: '二级 2-2'
}]
}, {
id: 3,
label: '一级 3',
children: [{
id: 7,
label: '二级 3-1'
}, {
id: 8,
label: '二级 3-2'
}]
}],
countent: "",
defaultProps: {
children: "children",
label: "label"
},
data1: new Array,
data2: "",
title: "水费电费水电费",
showScreen: true,
defaults: [],
defaultExpandAll:true };
},
methods: {
getcheckdata(data) {
//有多选框的时候返回的data数组
this.data1 = data;
},
getCurrentKey(data) {
//点击的时候返回当前点击的key
this.data2 = data;
},
getCheckedKeys(data) {
//有多选框时返回的key所组成的数组
this.data3 = data;
}
}
};
</script>

子组件

/*
* @property { data : {Array} 接口传来的数组 }
* @property { showCheckbox : {Boolean} 是否显示多选小方框 }
* @property { placeholder : {String} 提示语,上方搜索框提示语。 }
* @property { check : 父组件使用check来接收已选中的所有数据组成的数组 }
* @property { title : {String} 弹窗上方的名字 }
* @property { showScreen : {Boolean} 是否需要筛选框 }
* @property { nodeclick : 节点被点击时的回调 }
* @property { defaults : {Array} 默认选中的数据 传key组成的数组 }
* @property { defaultExpandAll : {Boolean} 是否默认展开 }
* @version 1.0.0
* @edit: 2018/8/2
*/
<template>
<div class="air-tree-wrappers">
<div class="el-dialog__title">{{ this.title }}</div>
<div v-if="screen">
<el-input class="input"
:placeholder="placeholder"
prefix-icon="el-icon-search"
v-model="filterText"
>
</el-input>
</div>
<el-tree class="filter-tree"
:data="data"
:props="defaultProps"
:show-checkbox="checkbox"
:default-expand-all="defaultExpandAll"
:filter-node-method="filterNode"
@check-change='check()'
ref="tree"
:node-key="'id'"
@node-click="nodeclick">
</el-tree>
<div class="foot">
</div>
</div>
</template>
<script>
export default {
props: {
placeholder: {
type: String
},
data: {
type: Array
},
default: {
type: Array
},
showCheckbox: {
type: Boolean
},
width: {
type: String
},
title: {
type: String
},
showScreen: {
type: Boolean
},
defaultExpandAll: {
type: Boolean,
}
},
data() {
return {
filterText: '',
countent: "",
checkbox: this.showCheckbox,
defaultProps: {
children: "children",
label: "label",
},
data1: new Array,
dialogTableVisible: false,
screen: this.showScreen
};
},
watch: {
filterText(val) {
this.$refs.tree.filter(val);
}
},
methods: {
filterNode(value, data) {
if (!value) return true;
return data.label.indexOf(value) !== -1;
},
//传回父组件
check() {
//获取所有被选中的data的数组
let takeDate = this.$refs.tree.getCheckedNodes();
this.$emit('check', takeDate);
//获取所有被选中的key的数组
let keyDate = this.$refs.tree.getCheckedKeys();
this.$emit('checkkey', keyDate);
},
nodeclick() {
let key = this.$refs.tree.getCurrentKey()
this.$emit('click', key);
}
}
};
</script>

里面用的事件都是element封好的直接用就好了比如

更多的事件,属性直接去element官网找就好了。

this.$nextTick(()=>{}) 这个方法的作用是 DOM更新完成后执行
应该就相当于一个延时函数,很有用,有时你的函数触发的时候dom还没加载出来比如使用$ref时候就会发生这种情况。

vue+element tree(树形控件)组件(2)的更多相关文章

  1. vue+element tree(树形控件)组件(1)

    最近做了第一个组内可以使用的组件,虽然是最简版,也废了不少力.各位前辈帮我解决问题,才勉强搞定.让我来记录这个树形组件的编写过程和期间用到的知识点. 首先说说需求,就是点击出现弹窗+蒙板,弹窗内容是一 ...

  2. 不依任何赖第三方,单纯用vue实现Tree 树形控件

    这几天接到一个需求,里面有需要做一个属性组件,找的第三方的,但是不能完全满足我的需求,有这时间,我就自己做个小轮子吧. 先看效果图(红点之前用的字体图标,是个对号,这里为了方便,用圆圈代替了选中状态, ...

  3. vue+element-ui之tree树形控件有关子节点和父节点之间的各种选中关系详解

    做后端管理系统,永远是最蛋疼.最复杂也最欠揍的事情,也永远是前端开发人员最苦逼.最无奈也最尿性的时刻.蛋疼的是需求变幻无穷,如同二师兄的三十六般变化:复杂的是开发难度寸步难行,如同蜀道难,难于上青天: ...

  4. Element ui tree树形控件获取当前节点id和父节点id

    低版本Element ui tree树形控件获取当前节点id和父节点id的方法:点击查看 最新版本Element ui tree树形控件获取当前节点id和父节点id教程: 1.找到node_modul ...

  5. vue_elementUI_ tree树形控件 获取选中的父节点ID

    el-tree 的 this.$refs.tree.getCheckedKeys() 只可以获取选中的id 无法获取选中的父节点ID想要获取选中父节点的id;需要如下操作1. 找到工程下的node_m ...

  6. ElementUI Tree树形控件renderContent return时报错

    问题描述: 使用Tree树形控件使用render-content渲染时return后报错或npm run dev时候报错,报错信息相同,如下: 问题分析: renderContent函数中需要使用js ...

  7. BootstrapBlazor实战 Tree树形控件使用(2)

    继续上篇实战BootstrapBlazor树型控件Tree内容, 本篇主要讲解整合Freesql orm快速制作数据库后台维护页面 demo演示的是Sqlite驱动,FreeSql支持多种数据库,My ...

  8. BootstrapBlazor实战-Tree树形控件使用(1)

    实战BootstrapBlazor树型控件Tree的使用, 以及整合Freesql orm快速制作数据库后台维护页面 demo演示的是Sqlite驱动,FreeSql支持多种数据库,MySql/Sql ...

  9. Element ui 使用 Tree 树形控件

    使用树形控件需要映入 jsx才能运行链接:https://github.com/vuejs/babel-plugin-transform-vue-jsx#usage npm install\ babe ...

随机推荐

  1. 博客框架 Hexo: 3.9.0 及主题 NexT 6.x.x 基本操作

    文章大纲 1. 不同代码仓库部署 coding 部署方式 项目名称 配置 SSH 公钥访问 git 仓库 github 码云 2. 手动cdn,智能解析 3. 添加评论系统 4. 博客置顶 5. 页脚 ...

  2. Games

    题目描述 Alice and Bob are playing a stone game. There are n piles of stones. In each turn, a player can ...

  3. jQ给下拉框绑定事件,为什么要绑定在框(select标签)上,而不是绑定在选项(option标签)上

    这是我在学习锋利的 jquery 书中 5.1.4 的代码时遇到的一个小问题,源代码如下: <head> <style type="text/css"> * ...

  4. 1)public,provite和protect不能放在函数函数头

    今天我才知道,原来这三个修饰的东西,只是用在类里面方法,怪不得一个叫方法,一个叫函数了,原来就是区分他们,哎, 今天遇到这么一个问题: <?php //header('Content-type: ...

  5. 陈天奇XGBoost文章解读(未完成)

    这个是我下载的原文在看,然后结合一些网上的资料学习,先贴一个网上的资料. 终于有人说清楚了XGBoost算法 XGBoost阅读之Weighted quantile sketch XGBoost论文翻 ...

  6. labview学习——用户界面模式

    根据事件的发出源,事件可以抽象地分为用户界面事件和用户自定义事件.相关的基本知识可以参考有关的书籍,这里不再阐述事件结构的使用方法. 下图所示的结构称为用户界面事件模式,它能够很便捷地响应各种事件并且 ...

  7. [LC] 136. Single Number

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  8. SHELL用法三(变量及参数设置)

    京峰JF2115-Day45上课笔记 1.SHELL编程变量命名规范: 变量分为:系统变量.环境变量.用户变量: 定义变量时使用=赋值,无需通过declare定义变量的类型: 变量赋值时,=前后是不能 ...

  9. whip|resist|patch|intimate|

    a piece of leather or rope that is fastened to a stick, used for hitting animals or people 鞭子,皮鞭 She ...

  10. leetcode 1.回文数-(easy)

    2019.7.11leetcode刷题 难度 easy 题目名称 回文数 题目摘要 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 思路 一些一定不为回文数的 ...