Vue.js學習(八)—— 樹形結構下拉框元件vue-treeselect
阿新 • • 發佈:2020-09-03
vue-treeselect是一個多選元件,具有對Vue.js的巢狀選項支援。
- 具有巢狀選項支援的單個和多個選擇
- 模糊匹配
- 非同步搜尋
- 延遲載入(僅在需要時載入深層選項的資料)
- 鍵盤支援(使用Arrow Up&Arrow Down鍵導航,使用鍵選擇選項Enter等)
- 豐富的選項和高度可定製
- 支援各種瀏覽器
需要Vue 2.2+
一、基本使用流程
1、首先npm'安裝依賴
npm install @riophae/vue-treeselect --save
2、然後在需要使用的元件中引入
import Treeselect from '@riophae/vue-treeselect' import'@riophae/vue-treeselect/dist/vue-treeselect.css'
3、宣告元件
components: { Treeselect }
4、使用
<treeselect :options="dataList" //接受陣列 placeholder="請選擇上級選單" v-model="form.parentId" />
二、樹結構下拉框示例
<treeselect :options="optionsMechanism" placeholder="select...." v-model="value"/>
data(){ return{ value:null, optionsMechanism:[{ id: 'fruits', label: 'Fruits', children: [ { id: '432673427163429080', label: 'Apple