el-select滑动加载更多 编辑页面取不到值得问题
<el-select v-model="ruleForm.region" placeholder="请选择品牌" style="width: 130px" v-loadmore="loadMore"> 绑定上一个事件 loadMore
页面内引入
Vue.directive('loadmore', {
bind(el, binding) {
// 获取element-ui定义好的scroll盒子
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()
}
})
}
})
在方法内部
loadMore: function() {
this.total2 += 2
this.brandlist(this.ruleForm.region);
},
这里的total2 是我定义的每页显示多少条
但是因为v-model 绑定的是一个id 会出现一种情况,比如咱们一次请求十条数据,在编辑页面的时候 页面回填,这个id 所在的位置在第十条以后,就导致我们去不到我们想要的内容 ,直接在上面显示一个id
这种请款下我们改的方法 第一个是判断在返回的数组内,有没有我们编辑时对应的那个数据,没有的话 我们定义一个我们想要的数组,把他给push 到我们请求到的对象内,
第二个方法和后台沟通一下 我们是把我需要的那个id 传给后台 让后台那块 把我需要的那条数据放在最前面就可以了