接口对接示例
async reqGetProductListByConditionOrNot() {
let res = await this.$API.finishedProduct.reqGetProductListByConditionOrNot(this.productParam)
if (res.code == '0') {
this.tableData = Array.isArray(res.responseBody.records) ? res.responseBody.records : []
this.productTotal = res.responseBody.total ? parseInt(res.responseBody.total) : 0
} else {
this.tableData = []
this.productTotal = 0
this.$apiMessage.error(res.message || '请求失败')
}
},
注意点:1、数据校验:对于后端传过来的数据,在赋值前应当对数据进行校验,判断其数据类型是否是前端页面需要的类型,比如上面前端需要的是数组类型,所以使用isArray方法进行判断,如果不是数组类型则赋值空数组。
2、数据转化:后端传过来的某些数据可能是字符串类型,而前端需要的是数值类型,比如上面的total,此时需要使用parseInt方法将其转换成数值类型,否则控制台会报错且页面上数据无法正常显示。