1、首先給 el-select 綁定一個事件,這個事件 element 是不支持的,所以要自己定義一個屬性:
directives: {
? ? 'el-select-loadmore': {
? ? ? inserted(el, binding) {
? ? ? ? const SELECTWRAP_DOM = el.querySelector(
? ? ? ? ? '.el-select-dropdown .el-select-dropdown__wrap'
? ? ? ? );
? ? ? ? SELECTWRAP_DOM.addEventListener('scroll', function() {
? ? ? ? ? const condition = this.scrollHeight - this.scrollTop <= this.clientHeight;
? ? ? ? ? if (condition) {
? ? ? ? ? ? binding.value(); }
? ? ? ? });
? ? ? }
? ? }
? }
2、在el-select中綁定這個屬性, loadmore 就是你的邏輯
<el-select v-el-select-loadmore="loadmore">
? ? ? // 你的代碼
</el-select>
3、loadmore 中寫自己的邏輯
當鼠標滑到 option 下面的時候,就會觸發(fā) loadmore 函數(shù),就可以實現(xiàn)鼠標下拉加載更多。
此文章出自:要怎么樣才能取一個獨一無二的名字
原文出處鏈接:http://blog.csdn.net/qq_35976676/article/details/108144988