前后台数据传递
前端代码(VUE)
前端方法
//查询数据
getWeighList() {
weighList(this.queryParams).then((response) => {
console.log(response);
if (response.data == 510 || response.code != 200) {
this.weighStart = false;
} else {
this.weighList = response.data;
this.weighList.forEach((weigh) => {
if (weigh.weighState != "01") {
this.weighStart = false;
}
});
}
});
},
前端URL
//查询数据
export function weighList(data) {
return request({
url: "/system/board/showStock",
method: "get",
params: data,
});
}
数据传递总结:
1、前端在get请求时使用params传递参数,在post请求时使用data传递参数。
2、weighList(this.queryParams).then((response) =>{})前面为传参,后面为收到参数。
3、传递参数时this.queryParams必须为对象,不能为常量,不然会导致后台无法收到数据。
4、在post传递下RequestBody收到参数如果为空,使用(required = false)依然可以收到空参数。