解决方法实际测试有效 让后端多返回一个当前请求的页码 与你要请求的页码是否相等
if (res.code == 10000) {
console.log(res);
if (this.page === res.data.page) {
if (this.page === 1) {
this.patentList = list;
} else {
this.patentList = [...this.patentList, ...list];
}
this.loading = false;
if (Math.ceil(num / 3) === this.page) {
this.finished = true;
}
this.page += 1;
}
}
全部代码
import _ from "lodash";
export default {
components: {},
name: "Brochure",
props: ["photo"],
data() {
return {
patentList: [],
photoType: [],
limit: 3,
page: 1,
type: "",
loading: false,
finished: false,
};
},
created() {
this.photoType = this.photo.cate;
},
watch: {
type() {
if (this.page === 1) {
this.finished = false;
this.patentList = [];
this.getList();
}
},
},
methods: {
getTitle(index, title) {
// console.log(index, title);
if (index === 0) {
// console.log("当前为零");
this.type = "";
} else {
this.type = title;
}
this.page = 1;
},
getList() {
this.loading = true;
console.log("被调用了", this.page);
this.$util.api(
"/app/bazaar/picture",
{
store_id: this.$route.query.id * 1,
limit: this.limit,
page: this.page,
type: this.type,
},
(res) => {
const { num, list } = res.data;
if (res.code == 10000) {
console.log(res);
if (this.page === res.data.page) {
if (this.page === 1) {
this.patentList = list;
} else {
this.patentList = [...this.patentList, ...list];
}
this.loading = false;
if (Math.ceil(num / 3) === this.page) {
this.finished = true;
}
this.page += 1;
}
}
}
);
},
onLoad: _.throttle(function () {
this.getList();
}, 1000),
},
};