element-ui怎么实现搜索功能?思路是什么?
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
![](https://devpress.csdnimg.cn/6deffb34f7114cc1a2e1e686a67e0027.png)
·
搜索实现思路
- 获取输入框的值(也称关键字)模糊搜索
- 通过事件触发将获取的值通过ajax请求搜索接口传递给后台
- 后台服务器通过服务端语言(node,PHP,Java)实现接收浏览器请求
- 后端语言查询数据库(Mysql,mongodb)
- 将查询的结果根据搜索接口约定好的json格式返回给浏览器
- 通过前端JS将返回的结果渲染展现到页面上
性能优化:可以利用防抖或节流,可以减少服务器压力 eg:lodash
<div class="search">
<el-input
placeholder="请输入内容"
v-model="input3"
v-model.trim="pageInfo.query"
class="input-with-select"
clearable
>
<el-button slot="append" icon="el-icon-search" @click="searchUser"></el-button>
</el-input>
<el-button class="aa" type="primary"">添加用户</el-button>
</div>
data值
input3: "",
// 搜索
searchUser: _.debounce(
function() {
// 调用获取全部数据的接口
this.getUserList();
},
3000,
{ leading: false }
),
_.throttle是lodash的节流方法
但是搜素最好用防抖 : _.debounce()
lodash的使用
npm install lodash -D
var _ = require('lodash');
或
import _ from 'lodash'
然后再vue组件中就可以使用了
![]( https://profile-avatar.csdnimg.cn/default.jpg)
![](https://devpress.csdnimg.cn/7174e1ca86c447029bb12f9ec0bd281c.png)
![](https://devpress.csdnimg.cn/096f7827187446559bd7b6030eb5db38.png)
![](https://devpress.csdnimg.cn/6deffb34f7114cc1a2e1e686a67e0027.png)
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:6 个月前 )
c345bb45
10 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 10 个月前
更多推荐
所有评论(0)