admin管理员组文章数量:1293888
I added a Bootstrap Vue Table to my app and wanted to log when the user switches to another page using the built in pagination.
/
For this, I added a @change
that is supposed to listen and log the v-model of the pagination, currentPage
. However, it seems to be called before currentPage
is actually updated.
How can I properly listen to this updating?
This is what I have tried: /
new Vue({
el: "#app",
data: {
totalRows: 50,
perPage: 10,
currentPage: 1
},
methods: {
pagination() {
console.log(this.currentPage);
},
}
})
<div id="app">
<div>
<b-pagination :total-rows="totalRows" :per-page="perPage" v-model="currentPage" @change="pagination" />
</div>
</div>
I added a Bootstrap Vue Table to my app and wanted to log when the user switches to another page using the built in pagination.
https://bootstrap-vue.js/docs/ponents/table/
For this, I added a @change
that is supposed to listen and log the v-model of the pagination, currentPage
. However, it seems to be called before currentPage
is actually updated.
How can I properly listen to this updating?
This is what I have tried: https://jsfiddle/eywraw8t/394424/
new Vue({
el: "#app",
data: {
totalRows: 50,
perPage: 10,
currentPage: 1
},
methods: {
pagination() {
console.log(this.currentPage);
},
}
})
<div id="app">
<div>
<b-pagination :total-rows="totalRows" :per-page="perPage" v-model="currentPage" @change="pagination" />
</div>
</div>
Share
Improve this question
edited Sep 26, 2018 at 8:29
Rence
asked Sep 26, 2018 at 6:41
RenceRence
2,9503 gold badges26 silver badges44 bronze badges
1 Answer
Reset to default 8You can watch currentPage
new Vue({
el: "#app",
data: {
totalRows: 50,
perPage: 10,
currentPage: 1
},
watch: {
currentPage: function (newVal) {
console.log('Change to page', newVal)
}
},
methods: {
setTo() {
this.currentPage = 1;
console.log(this.currentPage);
}
}
})
Check demo here
本文标签: javascriptVuejsWatch data changesStack Overflow
版权声明:本文标题:javascript - Vue.js - Watch data changes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741592100a2387189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论