当前位置: 首页 > news >正文

el-select 支持多选 搜索远程数据 组件抽取

el-select 支持多选 搜索远程数据 组件抽取

  • 使用方式
import selectView from './components/selectView'<el-form><el-form-item label="选择器"><selectView v-model="selValue" @change="handleChange"></el-form-item>
</el-form>
  • 组件
 <template><el-selectv-model="selectValue":multiple="multiple":filterable="true":remote="true"@focus="selectFocus":clearable="true":placeholder="placeholder":remote-method="remoteMethod":loading="selectLoading"@change="handleChange"style="width: 100%;"><el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option></el-select>
</template>
<script>
import { userListAll } from "@/utils/api.js";
export default {props: {// v-model绑定 返回 1,2,3 或 传入 1,2,3 id值value: {type: [String, Number],default: "",},placeholder: {type: String,default: "请选择",},multiple: {type: Boolean,default: true,},},computed: {currentValue: {get: function() {if (this.value) {return this.value.split(",");}return [];},set: function(val) {this.$emit("input", val.join(","));},},},data() {return {selectValue: "",options: [], //存储下拉框的数据selectEnterpriseForm: {nickName: "",},selectLoading: false,};},mounted() {this.selectEnterprise("");},methods: {selectEnterprise(query) {//query用户搜索的值this.selectEnterpriseForm = this.$options.data().selectEnterpriseForm; //清空数据this.selectEnterpriseForm.nickName = query;userListAll({...this.selectEnterpriseForm,}).then(res => {this.options = [];this.selectLoading = false;this.addLoading = false;res.data.forEach(element => {this.options.push({value: element.userId + "",label: element.nickName,});});if (this.currentValue.length > 0) {this.selectValue = this.currentValue;}}).catch(err => {});},remoteMethod(query) {this.selectLoading = true;this.selectEnterprise(query);},selectFocus() {this.options = [];this.selectLoading = true;this.selectEnterprise("");},handleChange(val) {this.currentValue = val;let nameList = [];val.forEach(item => {this.options.forEach(element => {if (item == element.value) {nameList.push(element.label);}});});// 将1,2,3 和 张三,李四,王五 返回this.$emit("change", val.join(","), nameList.join(","));},},
};
</script>
<style lang="scss" scoped>
// .con {
// 	display: inline-block;
// 	width: 100%;
// }
</style>
http://www.lryc.cn/news/161611.html

相关文章:

  • el-table纵向垂直表头
  • Pinyin4j介绍和简单使用
  • 【数据结构】查找
  • 第一次面试
  • Nacos配置文件更新+热更新+多环境配置共享+集群搭建
  • 李宏毅-机器学习hw4-self-attention结构-辨别600个speaker的身份
  • 记一次使用NetworkManager管理Ubuntu网络无效问题分析
  • Nginx重写功能
  • 王道考研计算机网络
  • 数据链路层重点协议-以太网
  • 学习计划
  • RabbitMQ的RPM包安装和Python读写操作
  • 文件上传漏洞案例
  • Office365 Excel中使用宏将汉字转拼音
  • baichuan2(百川2)本地部署的实战方案
  • PostgreSQL配置主从备份(docker)
  • qt作业day4
  • js如何实现字符串反转?
  • Nmap 7.94 发布:新功能!
  • 【深入解析spring cloud gateway】08 Reactor 知识扫盲
  • 常用ADB指令
  • 【HTML5高级第二篇】WebWorker多线程、EventSource事件推送、History历史操作
  • CentOS云服务器部署配置
  • 深入解析Java中的数组复制:System.arraycopy、Arrays.copyOf和Arrays.copyOfRange
  • libc和glibc有什么区别
  • 基于SSM的在线云音乐系统
  • 构建高效的BFF(Backend for Frontend):优化前端与后端协作
  • 喜报 | 实力亮相2023服贸会,擎创科技斩获领军人物奖创新案例奖
  • 科技革新自动驾驶:拓世AI智能助理携手跟您一起点亮未来之旅
  • 【HCIE】01.IGP高级特性