国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 幫助中心 > 正文

element-ui 遠程搜索組件el-select在項目中組件化的實現(xiàn)代碼

2024-07-09 22:42:12
字體:
供稿:網(wǎng)友

在項目中發(fā)現(xiàn)使用el-select時寫的比較多重復代碼,還有就是同一個頁面使用el-select會出現(xiàn)label值會顯示value值,
el-select組件化:

<template> <el-select  :class="obj&&keyword[keywordAttr.label]? 'selected': ''"  :value="keyword"  :placeholder="obj && keyword[keywordAttr.label]? keyword[keywordAttr.label]: placeholder"  filterable  :clearable="clear"  remote  :multiple="multiple"  :loading="selectLoading"  :reserve-keyword="reserve"  :remote-method="remoteMethod"  :  :disabled="disabled"  :value-key="keywordAttr.id"  @change="changeSelect"  @clear="handleClear"  @blur="handleBlur"  @focus="handleFocus"  @visible-change="handlerVisible" >  <el-option   v-for="item in keywordOptions"   :key="item[keywordAttr.id]"   :label="item[keywordAttr.label]"   :value="obj? item: item[keywordAttr.value]"   :disabled="item.disabled"  >   <slot :item="item"/>  </el-option> </el-select></template><script>export default { name: 'SelectRemote', props: {  value: {   type: [String, Object],   default: ''  },  reserve: {   type: Boolean,   default: true  },  clear: {   type: Boolean,   default: false  },  disabled: {   type: Boolean,   default: false  },  multiple: {   type: Boolean,   default: false  },  selectLoading: {   type: Boolean,   default: false  },  width: {   type: String,   default: '100%'  },  keywordOptions: {   type: Array,   default: function() {    return []   }  },  keywordAttr: {   type: Object,   required: true,   default: function() {    return {     id: '',     label: '',     value: ''    }   }  },  obj: {   type: Boolean,   default: false  },  placeholder: {   type: String,   default: function() { return '請輸入關(guān)鍵詞' }  } }, data() {  return {   keyword: this.value  } }, watch: {  value(newVal) {   this.keyword = newVal  } }, methods: {  remoteMethod(query) {   this.$emit('remoteMethod', query)  },  changeSelect(item) {   this.$emit('changeSelect', item)  },  handleClear() {   this.$emit('clear')  },  handleBlur() {   this.$emit('blur')  },  handleFocus() {   this.$emit('focus')  },  handlerVisible() {   this.$emit('visible-change')  } }}</script><style lang="scss" scoped>.selected ::-webkit-input-placeholder{ color: #606266 !important;}</style>

主要是使用了placeholder來顯示;

在父組件中:

<SeletcRemote       v-model="nodeOperate.saleEmp"       :keyword-attr="nodeObjPerson"       :keyword-options="empOptions"       :clear="true"       :obj="true"       :select-loading="selectLoading"       @remoteMethod="remoteMethod"       @changeSelect="handleProductChange($event, nodeOperate, 'saleEmp')"      />
nodeObjPerson: {  id: 'id',  label: 'empName'  }
handleProductChange(val, row, field) {   this.$set(row, field, val)  }

可以在單選的的狀態(tài)下完美解決了label顯示值;

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宝清县| 临海市| 图们市| 阳城县| 新津县| 西华县| 济宁市| 宁波市| 印江| 昌邑市| 德庆县| 奈曼旗| 襄垣县| 武川县| 无极县| 农安县| 宜黄县| 繁昌县| 商水县| 滁州市| 曲周县| 谢通门县| 马山县| 黎城县| 延吉市| 鄢陵县| 沁源县| 肥东县| 北票市| 江川县| 崇仁县| 古丈县| 扎囊县| 永昌县| 青海省| 天门市| 措美县| 沁源县| 平顺县| 泰宁县| 郴州市|