element-ui?實(shí)現(xiàn)輸入框下拉樹組件功能
用element-ui的 el-input,el-tree,el-popover組件組合封裝
@import url("http://unpkg.com/element-ui@2.15.14/lib/theme-chalk/index.css");
<script src="http://unpkg.com/vue@2/dist/vue.js"></script>
<script src="http://unpkg.com/element-ui@2.15.14/lib/index.js"></script>
<div id="app">
<el-popover
placement="bottom"
width="350"
trigger="click">
<el-tree
style="width:300px"
ref="tree"
:data="options"
:check-strictly="false"
show-checkbox
node-key="id"
:default-expanded-keys="[]"
:default-checked-keys="[]"
:props="{
children: 'children',
label: 'name'
}"
@check-change="handleCheckChage"
@node-click="handleNodeClick"
>
</el-tree>
<el-input slot="reference"
style="width:380px"
v-model="value.name"
placeholder="節(jié)點(diǎn)"
clearable
@clear="handleIptClear">
</el-input>
</el-popover>
</div>
var Main = {
data() {
return {
options: [
{id:'1', name: '1',
children:[
{id:'11', name: '11'},
{id:'12', name: '12'}
]
},
{id:'2', name: '2'}
],
value:{id:'', name: ''}
}
},
methods: {
// 清空輸入框內(nèi)容
handleIptClear(){
this.$refs.tree.setCheckedNodes([])
this.value.id = ''
this.value.name = ''
},
// checkbox被選中或取消選中
handleCheckChage(arg1, arg2, arg3){
const seltedNodes = this.$refs.tree.getCheckedNodes()
const ids = seltedNodes.map(n => n.id)
const names = seltedNodes.map(n => n.name)
this.value.id = ids
this.value.name = names
},
// 節(jié)點(diǎn)被點(diǎn)擊
handleNodeClick(arg1, arg2, arg3){
console.log('nodes:', arg1, arg2, arg3)
},
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
可以根據(jù)函數(shù)方法拿到里面的參數(shù),實(shí)現(xiàn)多選節(jié)點(diǎn)效果
到此這篇關(guān)于element-ui 實(shí)現(xiàn)輸入框下拉樹組件功能的文章就介紹到這了,更多相關(guān)element-ui 輸入框下拉樹組件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解webpack和webpack-simple中如何引入css文件
這篇文章主要介紹了詳解webpack和webpack-simple中如何引入css文件,非常具有實(shí)用價值,需要的朋友可以參考下2017-06-06
javascript合并兩個數(shù)組最簡單的實(shí)現(xiàn)方法
這篇文章主要介紹了javascript合并兩個數(shù)組最簡單的實(shí)現(xiàn)方法,方法很簡單,有需要的朋友們可以學(xué)習(xí)下。2019-09-09
基于JavaScript實(shí)現(xiàn)可搜索的表格
在Web開發(fā)中,數(shù)據(jù)表格是常見的數(shù)據(jù)展示形式,這篇文章主要為大家詳細(xì)介紹了如何使用JavaScript來實(shí)現(xiàn)這個功能,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01
w3c編程挑戰(zhàn)_初級腳本算法實(shí)戰(zhàn)篇
下面小編就為大家?guī)硪黄獁3c編程挑戰(zhàn)_初級腳本算法實(shí)戰(zhàn)篇。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06
微信小程序?qū)崿F(xiàn)點(diǎn)擊按鈕后修改顏色
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)點(diǎn)擊按鈕后修改顏色,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12

