vue+element tree(树形控件)组件(2)
今天记录组件的代码和一个调用它的父组件的代码,接口接收数据直接传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官网找就好了。
vue+element tree(树形控件)组件(2)的更多相关文章
- vue+element tree(树形控件)组件(1)
最近做了第一个组内可以使用的组件,虽然是最简版,也废了不少力.各位前辈帮我解决问题,才勉强搞定.让我来记录这个树形组件的编写过程和期间用到的知识点. 首先说说需求,就是点击出现弹窗+蒙板,弹窗内容是一 ...
- 不依任何赖第三方,单纯用vue实现Tree 树形控件
这几天接到一个需求,里面有需要做一个属性组件,找的第三方的,但是不能完全满足我的需求,有这时间,我就自己做个小轮子吧. 先看效果图(红点之前用的字体图标,是个对号,这里为了方便,用圆圈代替了选中状态, ...
- vue+element-ui之tree树形控件有关子节点和父节点之间的各种选中关系详解
做后端管理系统,永远是最蛋疼.最复杂也最欠揍的事情,也永远是前端开发人员最苦逼.最无奈也最尿性的时刻.蛋疼的是需求变幻无穷,如同二师兄的三十六般变化:复杂的是开发难度寸步难行,如同蜀道难,难于上青天: ...
- Element ui tree树形控件获取当前节点id和父节点id
低版本Element ui tree树形控件获取当前节点id和父节点id的方法:点击查看 最新版本Element ui tree树形控件获取当前节点id和父节点id教程: 1.找到node_modul ...
- vue_elementUI_ tree树形控件 获取选中的父节点ID
el-tree 的 this.$refs.tree.getCheckedKeys() 只可以获取选中的id 无法获取选中的父节点ID想要获取选中父节点的id;需要如下操作1. 找到工程下的node_m ...
- ElementUI Tree树形控件renderContent return时报错
问题描述: 使用Tree树形控件使用render-content渲染时return后报错或npm run dev时候报错,报错信息相同,如下: 问题分析: renderContent函数中需要使用js ...
- BootstrapBlazor实战 Tree树形控件使用(2)
继续上篇实战BootstrapBlazor树型控件Tree内容, 本篇主要讲解整合Freesql orm快速制作数据库后台维护页面 demo演示的是Sqlite驱动,FreeSql支持多种数据库,My ...
- BootstrapBlazor实战-Tree树形控件使用(1)
实战BootstrapBlazor树型控件Tree的使用, 以及整合Freesql orm快速制作数据库后台维护页面 demo演示的是Sqlite驱动,FreeSql支持多种数据库,MySql/Sql ...
- Element ui 使用 Tree 树形控件
使用树形控件需要映入 jsx才能运行链接:https://github.com/vuejs/babel-plugin-transform-vue-jsx#usage npm install\ babe ...
随机推荐
- mysql,user表中各字段的含义
1.查询user表 select * from mysql.user 2.修改用户密码 ALTER user ' 3.user表中各字段的含义 Select_priv:用户可以通过SELECT命令选择 ...
- jsp页面之间传中文参数显示乱码问题的解决
最近在项目中遇到jsp页面通过url传递参数,出现乱码,但是在本地是正常显示,在服务器上却是乱码,找了好久都没找到解决方法,最终在大神的帮助下解决了这个问题 比如从a.jsp像b.jsp页面传递参数 ...
- python+selenium自动化测试之登录
selenium_login.py import unittest from selenium import webdriver class LoginTest(unittest.TestCase): ...
- GPIO-FPGA架构
GPIO是一种软件运行期间能够动态配置和控制的通用引脚 有不同的GPIObank,每个GPIO口的bank都会有编号的区分, 每个GPIO口除了通用的输入输出功能以外,还有其他复用功能,例如GPIO5 ...
- @EnableGlobalMethodSecurity(prePostEnabled = true)
http://www.bubuko.com/infodetail-2243816.html
- LeetCode No.73,74,75
No.73 SetZeroes 矩阵置零 题目 给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 输入: [ [1,1,1], [ ...
- FastDFS安装部署
博主本人平和谦逊,热爱学习,读者阅读过程中发现错误的地方,请帮忙指出,感激不尽 服务器信息: Storage:192.168.247.20 Traker:192.168.247.21 一.搭建环境准备 ...
- django框架基础-路由系统-长期维护
################## 路由系统介绍 ####################### 路由系统就是路径和函数的对应关系, 路由系统可以看成支撑你这个网站的目录,就像是一本书一样 ...
- springboot学习笔记:4.logback日志配置
springboot中日志组件推荐使用logback: 由于springboot内置了logback,所以可以直接在application.properties中配置:如果要功能丰富些,则配置下log ...
- C语言返回值
C语言函数在结束的时候可以用一个数字表示运行的结果,这个数字就叫做函数的返回值. 主函数应该有一个返回值.如果这个返回值是0就表示程序希望计算机认为它正常结束,如果不是0就表示程序希望计算机认为它是出 ...