VUE插件vue-treeselect的使用及說(shuō)明
更新時(shí)間:2023年07月19日 14:38:15 作者:TING沫
這篇文章主要介紹了VUE插件vue-treeselect的使用及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。
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ū)域:"> <!--使用此插件過(guò)程中發(fā)現(xiàn)了一個(gè)新的問(wèn)題,可能會(huì)因?yàn)閷蛹?jí)樣式問(wèn)題在element組件中無(wú)法展示選項(xiàng)--> <!--修改方法就是將append-to-body的綁定值改為false--> <treeselect :append-to-body="true" v-model="searchForm.areaId" :options="areaAllList" :normalizer="normalizer" :show-count="true" placeholder="請(qǐng)選擇所屬區(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,否則輸入框中會(huì)提示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項(xiàng)目接口訪問(wèn)地址設(shè)置方式
這篇文章主要介紹了vue項(xiàng)目接口訪問(wèn)地址設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11vue元素實(shí)現(xiàn)動(dòng)畫(huà)過(guò)渡效果
這篇文章主要介紹了vue元素實(shí)現(xiàn)動(dòng)畫(huà)過(guò)渡效果,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07vue.js實(shí)現(xiàn)點(diǎn)擊后動(dòng)態(tài)添加class及刪除同級(jí)class的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue.js實(shí)現(xiàn)點(diǎn)擊后動(dòng)態(tài)添加class及刪除同級(jí)class的相關(guān)資料,需要的朋友可以參考下2018-04-04