最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue el-select與el-tree實現(xiàn)支持可搜索樹型

 更新時間:2022年08月18日 10:39:09   作者:范特西是只貓  
本文主要介紹了vue el-select與el-tree實現(xiàn)支持可搜索樹型,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1. 樹型下拉菜單

實現(xiàn)效果

2. vue頁面代碼

引入selectTree組件

import { selectTree } from '@/components'
export default {
  components: {
    selectTree
  },
  data() {
  	defaultData:{
  		managementStationId:'1478570186653609986',
  		managementStationName:'瀘彌監(jiān)控中心-安全'
  	}
  }
}

頁面使用

  • returnDropList 樹型菜單的值
  • managementStationId key值
  • defaultData 設(shè)置默認(rèn)值
  • treeProps 配置菜單
  • @handleNodeClick 選擇事件
<template>
	<div>
		<selectTree
		  style="width: 390px"
		  :treeList="returnDropList"
		  nodeKey="managementStationId"
		  :defaultData="defaultData"
		  :treeProps="{
		    children: 'children',
		    label: 'managementStationName'
		  }"
		  @handleNodeClick="selectDrop"
		></selectTree>
	</div>
</template>

3.樹型數(shù)據(jù)結(jié)構(gòu)

3. selectTree 組件代碼

<template>
  <el-select
    class="user-select-tree"
    v-model="textStr"
    :placeholder="placeholder"
    ref="select"
    :filterable="true"
    :remote="true"
    :remote-method="remoteMethod"
    :clearable="clearable"
    @clear="clearSelect"
    @visible-change="visibleChange"
    :popper-append-to-body="false"
    style="width: 100%"
  >
    <el-option
      v-model="value"
      style="
        height: 100%;
        max-height: 200px;
        overflow-y: auto;
        padding: 0;
        background-color: #ffffff;
      "
    >
      <el-tree
        :data="treeList"
        :props="treeProps"
        :filter-node-method="filterNode"
        :current-node-key="currentKey"
        highlight-current
        default-expand-all
        :node-key="nodeKey"
        ref="selectTree"
        :check-strictly="true"
        @node-click="handleTreeClick"
      >
        <span
          slot-scope="{ data }"
          :title="data[treeProps.label]"
          class="ellipsis"
        >
          {{ data[treeProps.label] }}
        </span>
      </el-tree>
    </el-option>
  </el-select>
</template>

<script>
export default {
  name: 'index',
  props: {
    treeList: {
      type: Array
    }, //樹形原始數(shù)據(jù)
    treeProps: Object, //樹形配置
    nodeKey: String, //樹形唯一鍵值
    defaultSelect: {
      //默認(rèn)選擇
      type: Boolean,
      default: true
    },
    defaultData: {
      type: Object,
      default: null
    },
    clearable: { type: Boolean, default: false },
    placeholder: { type: String, default: '請選擇' }
  },
  data() {
    return {
      textStr: '',
      value: '',
      filterText: '',
      currentKey: '',
      highlightNode: -1
    }
  },
  watch: {
    filterText(val) {
      this.$refs.selectTree.filter(val)
    },
    defaultData(val) {
      if (this.highlightNode === -1) {
       this.setEdit(val)
      }
    },
    treeList(val) {
      if (val.length > 0) {
        this.$nextTick(() => {
          if (this.defaultSelect) {
            this.value = val[0][this.treeProps.children][0][this.nodeKey]
            this.textStr =
              val[0][this.treeProps.children][0][this.treeProps.label]
            this.highlightNode = this.value
            this.currentKey = this.value
            this.$refs.selectTree.setCurrentKey(this.highlightNode)
            this.$emit('handleNodeClick', this.value)
          }
        })
      }
    }
  },

  methods: {
    setEdit(obj) {
      if (obj.name !== '' && obj.value !== '') {
        this.value = obj.value
        this.textStr = obj.name
        this.$nextTick(() => {
          this.highlightNode = this.value
          this.currentKey = this.value
          this.$refs.selectTree.setCurrentKey(this.highlightNode)
        })
      }
    },
    visibleChange() {
      this.filterText = ''
    },
    filterNode(value, data) {
      if (!value) return true
      return data[this.treeProps.label].indexOf(value) !== -1
    },
    remoteMethod(query) {
      setTimeout(() => {
        this.filterText = query
      }, 100)
    },
    // 設(shè)備類型點擊賦值
    handleTreeClick(data, checked) {
      this.filterText = ''
      if (checked) {
        // //判斷是否是父子
        if (
          data[this.treeProps.children] !== undefined &&
          data[this.treeProps.children].length !== 0
        ) {
          this.$refs.selectTree.setCurrentKey(this.highlightNode)
        } else {
          this.value = data[this.nodeKey]
          this.textStr = data[this.treeProps.label]
          this.$forceUpdate()
          this.currentKey = this.value
          this.highlightNode = data[this.nodeKey]
          this.$emit('handleNodeClick', this.value)
          this.$refs.selectTree.setCheckedKeys([this.highlightNode])
          this.$refs.select.blur()
        }
      }
    },
    clearFun() {
      this.value = ''
      this.textStr = ''
      this.currentKey = undefined
      this.highlightNode = undefined
      this.$refs.selectTree.setCurrentKey(this.highlightNode)
    },
    clearSelect() {
      this.value = ''
      this.textStr = ''
      this.$refs.selectTree.setCurrentKey()
      this.$emit('handleNodeClick', '')
    }
  }
}
</script>

<style scoped lang="scss">
.user-select-tree {
  ::v-deep {
    .el-icon-::before {
      content: '\ea1b';
      font-family: 'icomoon' !important;
      display: inline-block;
      -webkit-transform: scale(0.83);
      font-size: 10px;
      //width: 100%;
      //height: 100%;
      color: #666666;
      pointer-events: none;
    }
    .el-input.is-focus {
      .el-icon- {
        transform: rotate(0deg);
      }
    }
    .el-input__inner {
      height: 36px;
      line-height: 36px;
    }
    .el-input__icon {
      line-height: 36px;
    }
    .el-tree-node__content {
      height: 32px;
    }
  }
}
</style>

到此這篇關(guān)于vue el-select與el-tree實現(xiàn)支持可搜索樹型的文章就介紹到這了,更多相關(guān)vue 可搜索樹型內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue 使用 Mint UI 實現(xiàn)左滑刪除效果CellSwipe

    Vue 使用 Mint UI 實現(xiàn)左滑刪除效果CellSwipe

    這篇文章主要介紹了Vue 使用 Mint UI 實現(xiàn)左滑刪除效果CellSwipe,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2018-04-04
  • 詳解Vue.js和layui日期控件沖突問題解決辦法

    詳解Vue.js和layui日期控件沖突問題解決辦法

    這篇文章主要介紹了詳解Vue.js和layui日期控件沖突問題解決辦法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • vue?鼠標(biāo)移入移出(hover)切換顯示圖片問題

    vue?鼠標(biāo)移入移出(hover)切換顯示圖片問題

    這篇文章主要介紹了vue?鼠標(biāo)移入移出(hover)切換顯示圖片問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • VueJS設(shè)計與實現(xiàn)之淺響應(yīng)與深響應(yīng)詳解

    VueJS設(shè)計與實現(xiàn)之淺響應(yīng)與深響應(yīng)詳解

    這篇文章主要為大家介紹了VueJS設(shè)計與實現(xiàn)之淺響應(yīng)與深響應(yīng)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Vue組件間的樣式?jīng)_突污染問題詳解

    Vue組件間的樣式?jīng)_突污染問題詳解

    默認(rèn)情況下,寫在.vue組件中的樣式會全局生效,因此很容易造成多個組件之間的樣式?jīng)_突問題。導(dǎo)致組件之間樣式?jīng)_突的根本原因,我們接下來探究一下
    2022-11-11
  • node.js開發(fā)輔助工具nodemon安裝與配置詳解

    node.js開發(fā)輔助工具nodemon安裝與配置詳解

    node.js代碼修改后,需要重新啟動 Express 應(yīng)用,所做的修改才能生效。若之后的每次代碼修改都要重復(fù)這樣的操作,勢必會影響開發(fā)效率,本文將詳細(xì)介紹Nodemon,它會監(jiān)測項目中的所有文件,一旦發(fā)現(xiàn)文件有改動,Nodemon 會自動重啟應(yīng)用
    2020-02-02
  • Vue數(shù)字輸入框組件的使用方法

    Vue數(shù)字輸入框組件的使用方法

    這篇文章主要為大家詳細(xì)介紹了Vue數(shù)字輸入框組件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • 解決vue scoped scss 無效的問題

    解決vue scoped scss 無效的問題

    這篇文章主要介紹了解決vue scoped scss 無效的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Vben Admin 多標(biāo)簽頁狀態(tài)管理源碼學(xué)習(xí)

    Vben Admin 多標(biāo)簽頁狀態(tài)管理源碼學(xué)習(xí)

    這篇文章主要為大家介紹了Vben Admin 多標(biāo)簽頁狀態(tài)管理源碼學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • 手把手教你Vue3如何封裝組件

    手把手教你Vue3如何封裝組件

    vue2和vue3的組件封裝還是有區(qū)別,下面這篇文章主要給大家介紹了關(guān)于Vue3如何封裝組件的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue3具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2023-02-02

最新評論

安溪县| 蓬莱市| 蓝田县| 张家川| 孙吴县| 连州市| 云龙县| 磴口县| 车险| 洛宁县| 米泉市| 屯留县| 天峨县| 大英县| 申扎县| 比如县| 日喀则市| 平顶山市| 贺州市| 阆中市| 铜梁县| 沾益县| 万盛区| 巴东县| 平武县| 曲阳县| 扎兰屯市| 清苑县| 南木林县| 山东省| 保定市| 西华县| 杭锦后旗| 封开县| 伊宁县| 杭州市| 布尔津县| 镇康县| 高邑县| 宝清县| 凯里市|