VUE插件vue-treeselect的使用及說明
更新時(shí)間:2023年07月19日 14:38:15 作者:TING沫
這篇文章主要介紹了VUE插件vue-treeselect的使用及說明,具有很好的參考價(jià)值,希望對大家有所幫助。
VUE插件vue-treeselect使用
效果圖:
首先需要安裝:
npm install --save @riophae/vue-treeselect
用法看代碼注釋:
<template> <el-form ref="form" :model="searchForm" label-width="100px" :inline="true" :size="$formSize"> <el-form-item label="區(qū)域:"> <!--使用此插件過程中發(fā)現(xiàn)了一個(gè)新的問題,可能會因?yàn)閷蛹墭邮絾栴}在element組件中無法展示選項(xiàng)--> <!--修改方法就是將append-to-body的綁定值改為false--> <treeselect :append-to-body="true" v-model="searchForm.areaId" :options="areaAllList" :normalizer="normalizer" :show-count="true" placeholder="請選擇所屬區(qū)域" /> </el-form-item> </el-form> </template>
<script> //引入插件 import Treeselect from "@riophae/vue-treeselect"; import "@riophae/vue-treeselect/dist/vue-treeselect.css"; export default { //使用組件 components: { Treeselect }, data () { return { areaAllList: [], searchForm: { areaId: null,//綁定值必須為null,否則輸入框中會提示unkonwn }, } }, mounted () { this.getAreaAll() }, methods: { //轉(zhuǎn)換菜單數(shù)據(jù)結(jié)構(gòu) normalizer (node) { if (node.children && !node.children.length) { delete node.children; } return { id: node.areaId, label: node.areaName, children: node.children, }; }, //調(diào)用接口獲取select選項(xiàng)數(shù)據(jù) getAreaAll () { request({ url: `/manager/Area/AllAreaTree`, method: "get", }).then((res) => { if (res[SETTING.MANAGER_STATE] === SETTING.MANAGER_SUCCESS_STATE) { this.areaAllList = res.data; } else { this.$message({ type: "error", message: res.message || "操作失敗", }); } }); }, } } </script>
<style lang="scss" scoped> ::v-deep .vue-treeselect__control { max-width: 215px; } </style>
vue-treeselect樣式修改
<TreeSelect :appendToBody="true" class="treeselect-main" v-model="" :options="option" :normalizer="normalizer" :show-count="true" placeholder="選擇類別" />
//appendToBody 超出不隱藏
.treeselect-main { //防止污染 line-height: 27px; //字體控制 font-size: 12px; .vue-treeselect__placeholder { line-height: 27px; } .vue-treeselect__input{ line-height: 27px; } .vue-treeselect__control { height: 27px; } .vue-treeselect__single-value{ //選中后的樣式 line-height: 27px; } } .vue-treeselect__menu-container{ //浮層內(nèi)部樣式 寫在全局中 浮層被加入到了body里 font-size: 14px; color:#606266; font-weight: 100; }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue.js實(shí)現(xiàn)點(diǎn)擊后動態(tài)添加class及刪除同級class的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue.js實(shí)現(xiàn)點(diǎn)擊后動態(tài)添加class及刪除同級class的相關(guān)資料,需要的朋友可以參考下2018-04-04