简体   繁体   English

Vue.js-观看数据更改

[英]Vue.js - Watch data changes

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. 我在我的应用程序中添加了Bootstrap Vue表,并希望在用户使用内置分页切换到另一个页面时进行记录。

https://bootstrap-vue.js.org/docs/components/table/ https://bootstrap-vue.js.org/docs/components/table/

For this, I added a @change that is supposed to listen and log the v-model of the pagination, currentPage . 为此,我添加了一个@change ,它应该侦听并记录分页的v模型currentPage However, it seems to be called before currentPage is actually updated. 但是,它似乎在currentPage实际更新之前被调用。

How can I properly listen to this updating? 如何正确收听此更新?

This is what I have tried: https://jsfiddle.net/eywraw8t/394424/ 这是我尝试过的: https : //jsfiddle.net/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> 

You can watch currentPage 您可以观看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 在此处查看演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM