码迷,mamicode.com
首页 > 其他好文 > 详细

61、inputTree

时间:2020-10-21 21:08:59      阅读:21      评论:0      收藏:0      [点我收藏+]

标签:array   false   NPU   i++   project   绑定   scope   des   org   

<template>
  <div>
    <el-input :size="size" ref="selectInput" v-model="treeName" placeholder="请选择" readonly @click.native="projectOrgFun($event)" />
    <div>
        <el-tree
          v-show="ishowTree"
          ref="selectTree"
          v-model="treeId"
          node-key="id"
          :data="treeData"
          highlight-current
          :props="defaultProps"
          size="mini"
          @node-click="handleNodeClick"
        />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    //树形数据
    treeData: {
      type: Array,
      default: undefined
    },
    //树形选择框大小
   size: {
      type: String,
      default: "mini"
    }
  },
  data() {
    return {
      treeId: ‘‘,
      treeName: ‘‘, // 选中的节点名称
      ishowTree: false,
      defaultProps: {
        children: ‘children‘,
        label: ‘label‘
      },
      projectOrg: ‘‘
    }
  },
  created(){

  },
  methods: {
    // 点击输入框,展开树结构,绑定鼠标移出事件
    projectOrgFun(e) {
      var that = this
      if (that.ishowTree) {
        that.ishowTree = false
      } else {
        that.ishowTree = true
      }
      // 第一种方式:点击其他区域, 消失树
      this.$refs.selectInput.onclick = function() {
        that.projectOrgFalse()
      }
      e.stopPropagation()// 阻止冒泡
      // 离开区域的时候树消失
      that.$refs.selectTree.$el.onmouseleave = function() {
        that.projectOrgFalse()
      }
    },
    // 收起树并隐藏
    projectOrgFalse() {
      for (var i = 0; i < this.$refs.selectTree.store._getAllNodes().length; i++) {
        this.$refs.selectTree.store._getAllNodes()[i].expanded = false
      }
      this.ishowTree = false
    },
    // 点击树节点
    handleNodeClick(data) {
      this.treeId = data.id
      this.treeName = data.label
      this.ishowTree = false
      for (var i = 0; i < this.$refs.selectTree.store._getAllNodes().length; i++) {
        this.$refs.selectTree.store._getAllNodes()[i].expanded = false
      }
      this.$emit(‘nodeSelect‘, data)
    },
    // 监听树节点变化执行方法
    nodeChanged(data) {
      this.treeId = data.id
      this.treeName = data.name
      this.ishowTree = true
    }
  }
}
</script>
<style scoped>

</style>

  

61、inputTree

标签:array   false   NPU   i++   project   绑定   scope   des   org   

原文地址:https://www.cnblogs.com/gfbzs/p/13852000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!