javascript - VueJS BPagination - 每次更改 currentPage 时都会多次调用我的方法
问题描述
我有这个:
<template>
<div class="col-md-12" style="margin-bottom: 10px;">
<b-pagination
v-model="currentPage"
:total-rows="totalRows"
:per-page="perPage"
/>
</div>
</template>
<script>
data : function () {
return {
images: [],
isLoadingImage: true,
loadingText: "Please wait while we're loading the images...",
searchText : '',
currentPage: 1,
totalRows: 16,
perPage: 50,
}
},
watch : {
currentPage (to, from) {
this.searchImage();
},
},
mounted() {
this.searchImage();
},
methods : {
searchImage() {
let _this = this;
this.isLoadingImage = true;
MyCustomService.showImage(this.searchText,this.currentPage).then(function(result){
_this.isLoadingImage = false;
_this.images = result.data.results;
_this.totalRows = result.data.page.totalitems;
_this.perPage = result.data.page.itemsperpage;
});
}
}
</script>
我注意到,当我点击分页上的数字时,这个:
它调用了searchImage()
两次。因此,当我想转到第 2 页时,这使得currentPage
= 2
,它转到 page2
然后它重置回1
.
顺便说一句 - 这MyCustomService.showImage()
是一个async
函数,不确定它是否会给你额外的信息。
这是为什么?我认为我的代码非常简单,但我得到了这个奇怪的结果。
如果您需要进一步澄清,请告诉我,我很乐意添加一些信息。
谢谢,非常感谢您的帮助!
解决方案
推荐阅读
- c - 如何解决 C 中的 libcurl 错误(Curl_easy_perform 43)
- wix - Wix Bootstrapper(Burn)标签的条件显示
- python - Subprocess.run 不适用于 ssh-copy-id
- google-sheets - 如何在 Google 表格中使用数字格式来显示未简化的非约简分数?
- mockito - 即使我认为我没有提供正确的模拟,为什么测试用例仍然通过
- java - JAVA SpringBoot:当在 Docker 中时,liquibase 插件运行时出现错误并且不执行更改日志
- android - 安装 react-native-router-flux 后出错
- vue.js - 使用 vee-validate 验证 vue-select
- git - 使用 git merge --continue 而不是 git rebase --continue
- javascript - 优化JS文件