直接上代码
<template>
<div class="content">
<el-select v-model="value"
v-el-select-loadmore="loadMore()"
placeholder="请选择">
<el-option v-for="(item,index) in list.slice(0,rangeNumber)"
:key="index"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</div>
</template>
<script>
import Vue from 'vue';
Vue.directive('el-select-loadmore', {
bind: function (el, binding) {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
SELECTWRAP_DOM.addEventListener('scroll', function () {
console.log(this)
const condition = (this.scrollHeight - this.scrollTop) <= this.clientHeight ? true : false;
if (condition) binding.value();
});
}
})
export default {
data () {
return {
list: [
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
{ id: 2086, name: "KTV" },
{ id: 2069, name: "NBA" },
],
value: '',
rangeNumber: 10,
}
},
methods: {
loadMore () {
return () => this.rangeNumber += 5
},
},
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
<!--
新建directive.js文件
全局注册,页面直接v-xxx使用
export default (vue) => {
}
-->