当前位置: 首页 > 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;});
});

http://www.lryc.cn/news/406124.html

相关文章:

  • 国科大作业考试资料-人工智能原理与算法-2024新编-第五次作业整理
  • C++五子棋(未做完,但能玩,而且还不错)
  • 二分查找代码详解
  • uniapp的h5,读取本地txt带标签的文件
  • 韦东山嵌入式linux系列-具体单板的按键驱动程序(查询方式)
  • 如何使用 API list 极狐GitLab 群组中的镜像仓库?
  • PHP设计模式-简单工厂模式
  • C语言航空售票系统
  • Oracle 19c打Datapatch数据补丁报错处理
  • Linux shell编程学习笔记66:ping命令 超详细的选项说明
  • SSL/TLS和SSL VPN
  • 浅谈WebSerice
  • linux快速入门-学习笔记
  • 科普文:5种Linux下软件部署方式说明
  • Redisson中的RBlockingQueue的使用场景及例子
  • 【办公软件】Office 2019以上版本PPT 做平滑切换
  • connect-multiparty中间件用法以及实例--文件上传中间件(保姆级别教学)
  • 0503触发器的电路结构和工作原理
  • LeetCode:二叉树的中序遍历(C语言)
  • MySQL数据库基本安装与部署
  • paraFoam 运行 报错 usr/lib/x86_64-linux-gnu/libQt5Core.so 已解决
  • 科技前沿:Llama 3.1的突破与革新
  • 每天一个数据分析题(四百四十七)- 业务系统
  • 如何保护你的网络安全?
  • Nginx 怎样处理请求的重试机制?
  • 自己开发软件实现网站抓取m3u8链接
  • [Python3] 多模式字符串搜索 `Aho-Corasick`
  • 4 Types of Kaggle Competitions
  • 【STM32】stm32中GPIO_ReadInputDataBit()是什么意思
  • Study--Oracle-07-ASM相关参数(三)