参考:
https://www.jianshu.com/p/74dda01d2faf
https://blog.csdn.net/qq_41287158/article/details/125046149
https://blog.csdn.net/cherry_zhang18/article/details/120907452
问题:
- 回显问题
<el-select v-model="searchParams.productCode"
placeholder="请选择产品"
clearable
filterable
v-loadmore="loadMore"
@change="changeProduct">
<el-option v-for="item in productList"
:key="item.code"
:label="item.name"
:value="item.code">
</el-option>
<!--加载中的item不可选中状态-->
<el-option v-if="isLoading" disabled>
加载中-Loading...
</el-option>
</el-select>
// data
productList: [], // List
productPagination: { // 分页信息
current: 1,
size: 10,
total: 0,
},
isLoading: false, // 是否加载中
/***
* 加载更多
*/
loadMore () {
console.log('loadMore执行了')
// 如果正在加载中的时候,直接return,防止网速慢,一次加载很多页的问题
if (this.isLoading) {
return false
}
if (this.productPagination.total > this.productList.length) {
this.productPagination.current += 1
this.getProductList()
}
},
/**
* 获取产品列表 list
*/
async getProductList () {
const params = {
current: this.productPagination.current,
size: this.productPagination.size,
}
this.isLoading = true
let res = await getProductList(params) // getDeviceList
if (this.productPagination.current == 1) {
this.productList = res.data.records || []
} else {
this.productList.push(...res.data.records || [])
}
this.isLoading = false
this.productPagination.total = res.data.total || 0
},
// 指令
directives: {
'loadmore': {
bind (el, binding) {
console.log('el:', el)
console.log('binding:', binding.value)
const selectDom = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
selectDom.addEventListener('scroll', () => {
/**
* scrollHeight 获取元素内容高度(只读)
* scrollTop 获取或者设置元素的偏移值,常用于, 计算滚动条的位置, 当一个元素的容器没有产生垂直方向的滚动条, 那它的scrollTop的值默认为0.
* clientHeight 读取元素的可见高度(只读)
* 如果元素滚动到底, 下面等式返回true, 没有则返回false:
* ele.scrollHeight - ele.scrollTop === ele.clientHeight;
*/
console.log('scrollHeight:', selectDom.scrollHeight, 'scrollTop:', selectDom.scrollTop, 'clientHeight:', selectDom.clientHeight)
const condition = selectDom.scrollHeight - selectDom.scrollTop <= selectDom.clientHeight
if (condition) {
binding.value()
}
})
}
}
},
问题:
1.如果select是模糊搜索,怎么记录搜索的内容呢?