elementUI vue tree input 懒加载 输入下拉树…
2018-10-29 15:27:34来源:博客园 阅读 ()
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>Title</title> <!-- import CSS --> <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"> <style> .el-tree{ position:absolute; cursor:default; background:#fff; color:#606266; z-index:100; border:1px solid #dcdfe6; border-radius:5px; width:100%; } </style> </head> <body> <div id="app"> <el-form ref="projectOrg" v-model="projectOrg" label-width="140px" size="mini"> <el-form-item ref="treeParent" label="维护机构" prop="projectOrg"> <el-input @click.native="projectOrgFun" v-model="searchOrgId" placeholder="请输入维护机构" readonly></el-input> <el-tree v-show="ishowTree" show-checkbox lazy ref="tree" highlight-current @check-change="currentchange" :load="getOrgList" @node-click="handleNodeClick" :props="defaultProps"> </el-tree> </el-form-item> </el-form> </div> <!-- import Vue before Element --> <script src="https://unpkg.com/vue/dist/vue.js"></script> <!-- import JavaScript --> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <script> new Vue({ el: '#app', data: function () { return { input: [], searchOrgId: '', //保存被选中的ID, 提交的时候按字符串提交: // var organCodesList=this.organCodes.join(","), // 后台解析的时候使用: //String[] organCodes=organCodesList.split(","); organCodes: [], ishowTree: false, defaultProps: { children: 'children', label: 'label', }, projectOrg: '', } }, //加载完成时调用 created: function () { }, //方法 methods: { //树型点击 currentchange(data, ischeck) { console.log(data); if (!ischeck) { var index = this.input.findIndex(d => d === data.label); this.input.splice(index, 1); this.organCodes.splice(index, 1); } else { this.input.push(data.label); this.organCodes.push(data.id); } console.log(this.organCodes); var that = this; that.$refs.tree.$el.onmouseleave = function () { that.ishowTree = false; } that.searchOrgId = this.input.toString(); }, projectOrgFun() { if(this.ishowTree){ this.ishowTree = false; }else{ this.ishowTree = true; } var that = this; that.$refs.tree.$el.onmouseleave = function () { that.ishowTree = false; } that.$refs.treeParent.$el.onmouseleave = function () { that.ishowTree = false; } }, projectOrgFalse(){ this.ishowTree = false; }, handleNodeClick(data) { console.log(data); }, getOrgList(node, resolve) { let that = this; console.log(node); //等于0表示根节点 if (node.level == 0) { //请求数据 // that.getFirstRootNodeData(resolve); //模拟数据 var FirstRootNodeData = [{ id: '1', label: "初始根节点01" }, { id: '2', label: "初始根节点02" }]; resolve(FirstRootNodeData); //直接返回 return; } else { //请求数据(传送要请求的根节点的id) console.log(node.data.id); // that.getLeafNodeData(node.data.id,resolve); //模拟数据 var LeafNodeData = [{ id: '1', label: "叶子节点01" }, { id: '2', label: "叶子节点02" }, { id: '2', label: "叶子节点02" }]; resolve(LeafNodeData); return; } } }, }) </script> </body> </html>
显示效果:
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:javascript中函数的写法
- vue.js开发环境搭建教程 2020-03-16
- Vue input控件通过value绑定动态属性及修饰符的方法 2020-03-05
- 详解Webstorm 新建.vue文件支持高亮vue语法和es6语法 2020-02-07
- vue路由跳转时判断用户是否登录功能的实现 2020-01-17
- vue-cli中打包图片路径错误的解决方法 2020-01-17
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash