之前在公司开发功能的时候,发现了一个通用业务的问题
带有条件输入框,或者选项框,通过点击查询按钮 , 渲染列表分页的时候,通常会遇到一个BUG
当我选择或者输入了查询条件的时候 ,直接不点击查询按钮 , 直接点击分页的时候 , 会直接进行一个带有条件的查询 , 实际上这样的做法是有问题的
解决方案:
通过双条件对象,深拷贝,分页和查询走两个方法即可消除
data(){
return{
formInline:{}, // 条件查询对象
pageForm:{}, // 分层深拷贝对象
pageValue: { pageSize: 10, total: 0, pageNum: 1 },
}
}
mounted(){
// 请求列表接口
this.getTableList();
},
methods:{
// 条件查询
getTableList(){
let data = {
...this.pageValue,
...this.pageForm,
};
// 接口赋值等逻辑
....
},
// 点击按钮进行查询
onSearch(){
// 点击按钮的时候,深拷贝赋值,保留点击查询后的数据
this.pageForm = JSON.parse(JSON.stringify(this.formInline));
let data = {
...this.pageValue,
...this.formInline,
};
// 接口赋值等逻辑
....
},
// 重置数据按钮
resetForm(formName) {
this.$refs[formName].resetFields();
this.pageForm = {};
this.getTableList();
},
// 其余所有接口
// 涉及到类似重新请求的,基本都走getTableList() 接口即可
}