關(guān)于el-select 與el-tree組合可篩選組件

1605166703.jpg

1605167577(1).jpg
           <el-select
               v-model="formData.productClassId"
               clearable
               @clear="selectClear"
               placeholder="請選擇">
               <el-option
                   :label="productName"
                   :value="formData.productClassId"  class="option-style">
                   <el-input
                     placeholder="輸入關(guān)鍵字搜索"
                     v-model="filterText" @click.stop.native class="sel">
                   </el-input>
                   <el-tree
                     class="filter-tree"
                     :data="optionData"  //樹形數(shù)據(jù)
                     :props="defaultProps" 
                     default-expand-all
                     :filter-node-method="filterNode" //節(jié)點篩選方法
                     @node-click="nodeClick"
                     ref="tree">
                      <div slot-scope="{node, data}">
                        <span :class="[{'tree-click': treeClick==data.value}]">{{data.className}}</span>  //className 為props中l(wèi)abel的字段名
                    </div>
                   </el-tree>
                   </el-option>
           </el-select>
     export dafault {
           data () {
               return {
                 filterText:'',//input輸入框輸入的篩選字段
                  treeClick: null,
                defaultProps: {  
                   value: 'id',
                   label: 'className',
                   children:'productClassList'
               },
             productName:'' //el-select option顯示的選項
           },
          watch: {
               filterText(val) {
                 this.$refs.tree.filter(val);
               }
           },
         methods: {
             filterNode(value, data) {
             if (!value) return true;
               return data.className.indexOf(value) !== -1;
             },
         //下拉選項點擊事件
         nodeClick(obj, node){
          this.treeClick = obj.id;
           this.formData.productClassId = obj.id
           this.productName = obj.className
        },
     //清空el-select 選中的值
        selectClear(){
         this.treeClick = '';
         this.formData.productClassId = ''
         this.productName = ''
         this.filterText = ''
          },
       }
       }
<style scoped>
.option-style{
 padding: 0;
 width: 100%;
 height: 100%;
 background-color: #FFFFFF;
}
/deep/.sel .el-input__inner{
 width: 90%;
   margin-left: 5%;
}
</style>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容