若依vue前端queryParams搜索下拉框无法重置或者重置值有问题
在A页面点击查看详情跳B页面,发现如果选择不同行跳转的话,点击重置按钮,下拉框里面的值会变成第一次进来的值。找了一圈没找到答案。
最后试了一下在resetQuery方法里面给queryParams重新赋上一个对象,发现可以正常重置了,能保证值不会改变,还有从菜单点进去重置值会消失。
代码如下:
resetQuery() {
// 给queryParams重新赋值,而不是对queryParams里面的某个属性重新赋值
const _this = this;
this.queryParams = {
pageNum: _this.queryParams.pageNum,
pageSize: _this.queryParams.pageSize,
topicId: null
}
if (!!this.topicId) {
this.queryParams.topicId = this.topicId
this.resetForm("queryForm", "topicId");
} else {
this.resetForm("queryForm");
}
this.handleQuery();
},