2018年12月12日
暂时把最近项目上写的一些简单需求做个总结
1.搜索框,进行模糊搜索(使用vue实现,vue自定义指令,做函数防抖优化)
<input type="text" v-throttle="search" id="entityId" placeholder="请输入" v-model="company">
directives: {
// 自定义函数防抖指令
throttle: {
inserted (el, binding) {
let timer
el.addEventListener('keydown', () => {
clearTimeout(timer)
timer = setTimeout(() => {
binding.value()
}, 300)
})
}
}
}
// 模糊查询请求
search () {
if (this.company.length > 0) {
searchProperties(this.company, this.graphName)
.then((res) => {
this.searchCompanies = []
for (let key in res) {
res[key].forEach((val) => {
if (this.searchCompanies.length < 10) {
this.searchCompanies.push(val)
}
this.isKeyUp = true
})
}
})
} else {
this.isKeyUp = false
}
}
下次再改