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

vue 搜索框

 效果

  1. 创建搜索组件
    • 在Vue项目中,首先需要创建一个搜索组件。这个组件通常包含一个输入框和一个搜索按钮。
    • 使用v-model指令将输入框与组件的数据属性(如searchKeyword)进行双向绑定,以便获取用户输入的关键词。
  2. 处理搜索逻辑
    • 为搜索按钮绑定一个点击事件处理函数(如handleSearch),该函数负责在用户点击时触发搜索操作。
    • 在事件处理函数中,可以使用Vue的异步请求库(如Axios)向后端服务器发送搜索请求,并将用户输入的关键词作为请求参数。
  3. 展示搜索结果
    • 后端服务器处理搜索请求后,将返回搜索结果。
    • 在Vue组件中,可以使用计算属性(computed properties)或观察者(watchers)来监听搜索结果的变化,并相应地更新组件的模板以展示搜索结果。
  4. 优化搜索体验
    • 可以为搜索组件添加一些辅助功能,如自动完成、搜索历史记录等,以提升用户体验。
    • 使用正则表达式或模糊匹配算法来实现更复杂的搜索逻辑。
<div class="top-wrapper"><div class="search el-input el-input--suffix"><inputtype="text"autocomplete="off"placeholder="输入指标名称搜索"class="el-input__inner"v-model="searchKeyword"@keydown.enter="search"@change="searchChange"/><span class="el-input__suffix"><span class="el-input__suffix-inner"><el-icon @click="search"><Search /></el-icon></span></span></div></div>
.top-wrapper {display: flex;justify-content: flex-start;margin-bottom: 16px;
}.top-wrapper .search {width: 250px;
}
.el-input .el-input__suffix .el-input__icon {line-height: 32px;
}.el-input__icon {height: 100%;width: 25px;text-align: center;transition: all 0.3s;line-height: 40px;
}
.el-input__suffix {right: 5px;transition: all 0.3s;pointer-events: none;
}.el-input__prefix,
.el-input__suffix {position: absolute;top: 0;-webkit-transition: all 0.3s;height: 100%;color: #c0c4cc;text-align: center;
}.el-input__suffix-inner {pointer-events: all;
}.el-input__icon:after {content: "";height: 100%;width: 0;display: inline-block;vertical-align: middle;
}
.top-wrapper {display: flex;justify-content: flex-start;margin-bottom: 16px;
}.top-wrapper .search {width: 250px;
}.el-input {position: relative;font-size: 14px;
}.el-input__inner {-webkit-appearance: none;background-color: #fff;background-image: none;border-radius: 4px;border: 1px solid #dcdfe6;box-sizing: border-box;color: #606266;display: inline-block;height: 40px;line-height: 40px;outline: 0;padding: 0 15px;transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);width: 100%;font-size: inherit;-webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}.el-dialog .el-dialog__body .el-input .el-input__inner {padding-left: 8px;color: #333;
}.el-input .el-input__inner {height: 32px;line-height: 32px;border-radius: 2px;
}
const columnsList = ref([]);
const searchKeyword = ref<string>("");
const keyword = ref<string>("");
const leftGroups = ref([]);
const rightGroups = (groupName) => {return columns.filter((item) =>searchKeyword.value? item.groupName == groupName && item.label.indexOf(searchKeyword.value) > -1: item.groupName == groupName).sort((a, b) => a.orderNum - b.orderNum);
};
const searchChange = () => {columnsList.value = columns.filter((item) => item.label.indexOf(searchKeyword.value) > -1);
};
const search = () => {columnsList.value = columns.filter((item) => item.label.indexOf(searchKeyword.value) > -1);
};
const lockList = ref([]);
onMounted(() => {columnsList.value = columns;
});
watchEffect(() => {if(searchKeyword.value){columnsList.value = columns.filter((item) => item.label.indexOf(searchKeyword.value) > -1);}if(!searchKeyword.value){columnsList.value = columns;}drag.value = columns.filter((item) => item.checked && !item.disabled);lockList.value = columns.filter((item) => item.disabled).sort((a, b) => a.orderNum - b.orderNum);const seen = new Set();leftGroups.value = columnsList.value.map((item) => {return {prop: item.prop,groupName: item.groupName,checked: false,orderNum: item.orderNum,active: item.active ? item.active : false};}).filter((item) => {if (!seen.has(item.groupName)) {seen.add(item.groupName);return true;}return false;});
});

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【Linux】gcc简介+编译过程
  • VIsual Studio:为同一解决方案下多个项目分别指定不同的编译器
  • 音视频入门基础:H.264专题(15)——FFmpeg源码中通过SPS属性获取视频帧率的实现
  • Varjo XR-4系列现已获得达索3DEXPERIENCE平台官方支持
  • 计算机网络-配置路由器ACL(访问控制列表)
  • 美摄科技企业级视频拍摄与编辑SDK解决方案
  • bug bug bug
  • 基于 HTML+ECharts 实现的大数据可视化平台模板(含源码)
  • 如何优化 Selenium 和 BeautifulSoup 的集成以提高数据抓取的效率?
  • MySQL:在 SELECT 查询中过滤数据
  • 在qt的c++程序嵌入一个qml窗口
  • https改造-python https 改造
  • docker容器与宿主机时间同步
  • etcd节点通信的协议和端口
  • 电脑屏幕录制软件,分享4款(2024最新)
  • (ckeditor+ckfinder用法)Jquery,js获取ckeditor值
  • 230. Kth Smallest Element in a BST
  • Effective Java 笔记(一)
  • Go 语言编译器的 //go: 详解
  • input的行数自动增减
  • Java 实战开发之spring、logback配置及chrome开发神器(六)
  • JAVA_NIO系列——Channel和Buffer详解
  • JavaScript创建对象的四种方式
  • Meteor的表单提交:Form
  • python 学习笔记 - Queue Pipes,进程间通讯
  • Python学习之路16-使用API
  • Sass 快速入门教程
  • Spring-boot 启动时碰到的错误
  • vue-cli在webpack的配置文件探究
  • 工作踩坑系列——https访问遇到“已阻止载入混合活动内容”
  • 工作手记之html2canvas使用概述
  • 近期前端发展计划
  • 理清楚Vue的结构
  • 力扣(LeetCode)357
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 三栏布局总结
  • 智能合约Solidity教程-事件和日志(一)
  • AI又要和人类“对打”,Deepmind宣布《星战Ⅱ》即将开始 ...
  • ​ubuntu下安装kvm虚拟机
  • ​马来语翻译中文去哪比较好?
  • ​什么是bug?bug的源头在哪里?
  • # C++之functional库用法整理
  • #define 用法
  • (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)...
  • (JSP)EL——优化登录界面,获取对象,获取数据
  • (Mirage系列之二)VMware Horizon Mirage的经典用户用例及真实案例分析
  • (Windows环境)FFMPEG编译,包含编译x264以及x265
  • (附程序)AD采集中的10种经典软件滤波程序优缺点分析
  • (学习总结16)C++模版2
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • .axf 转化 .bin文件 的方法
  • .gitignore文件---让git自动忽略指定文件
  • .NET I/O 学习笔记:对文件和目录进行解压缩操作
  • .NET 表达式计算:Expression Evaluator
  • .net6+aspose.words导出word并转pdf