item-provider is called twice?
See original GitHub issueDescribe the bug
The item provider for b-table is called twice.
Steps to reproduce the bug
This is the b-table
:
<b-table
:items="itemProvider"
:busy.sync="isBusy"
:fields="fields"
:sort-by.sync="sortBy"
:sort-desc.sync="sortDesc"
:striped="true"
:bordered="true"
:current-page="pagination.current_page"
:per-page="pagination.per_page"
class="card-table">
<template slot="status" slot-scope="data">
<b-badge variant="outline-success" v-if="data.item.status === 'active'">Active</b-badge>
<b-badge variant="outline-danger" v-if="data.item.status === 'inactive'">Inactive</b-badge>
</template>
</b-table>
Method:
itemProvider () {
this.isBusy = true;
//if I add console.log("Test"); here, it's displayed twice, too.
let promise = axios.get ('/users/index?page=' + this.pagination.current_page);
return promise.then (resp => {
let items = resp.data.data;
this.pagination.current_page = resp.data.current_page;
this.pagination.last_page = resp.data.last_page;
this.pagination.per_page = resp.data.per_page;
this.pagination.total = resp.data.total;
this.isBusy = false;
return items
}).catch (error => {
this.isBusy = false;
return [];
})
},
Expected behavior
Route is called only once.
Versions
Libraries:
- BootstrapVue: 2.0.0-rc.1
- Bootstrap: 4.3.1
- Vue: 2.6.6
Environment:
- Device: MacBook
- OS: macOS Mojave
- Browser: Safari
- Version: 12.1 (14607.1.40.1.4)
Additional context
I just found out that the double-call is removed if I remove :current-page="pagination.current_page"
?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
SwiftUI onDrag being called twice - Stack Overflow
I'm implementing Drag & Drop using SwiftUI. The problem I'm facing is that onDrag is called twice: The first time is when long...
Read more >getTimeline called twice on load | Apple Developer Forums
When I run my widget from xcode I see getTimeline is called twice for some reason. It's called the first time, then after...
Read more >Difference Between Stub, Mock, and Spy in Spock Framework
So generally, this line says: itemProvider.getItems will be called once with ['item-'id'] argument and return given array. We already know that ...
Read more >Adding support for multiple windows to your iPadOS app
The default scene configuration is called Default Configuration and uses the $(PRODUCT_MODULE_NAME).SceneDelegate object to set up its scene and ...
Read more >The Complete Guide of PHPicker in iOS 14 - AppCoda
Each one of them contains a property called itemProvider , which is an ... You can do that multiple times; all of them...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In your case, it is probably because you are setting the pagination parameters in the provider (in the
then
), which is triggering b-table to re-fetch the data, as the parameters (i.e. per page, current_page, etc) are being updated with values that might be different (i.e. a number as string vs a number)One solution, when you use props to rewrite default
sortBy
,sortDesc
and other variables.Use condition
<b-table v-if="tableReady" ...>
in template. AddtableReady: false
to your data object. Addthis.tableReady = true;
after code that sets your props.