vue-hackernews-2.0 icon indicating copy to clipboard operation
vue-hackernews-2.0 copied to clipboard

Why did `FETCH_LIST_DATA` action fires twice on page switching?

Open zckevin opened this issue 5 years ago • 0 comments

In file src/entry-client.js, we have beforeRouteUpdate mixin:

Vue.mixin({
  beforeRouteUpdate (to, from, next) {
    const { asyncData } = this.$options
    if (asyncData) {
      asyncData({
        store: this.$store,
        route: to
      }).then(next).catch(next)
    } else {
      next()
    }
  }
})

And in src/views/ItemList.vue, we have been watching for vue-router's page:

  watch: {
    page (to, from) {
      this.loadItems(to, from)
    }
  },

And I thought these two code fragments are doing the same thing, is it just for demonstrating or other purposes? Thanks!

zckevin avatar Jun 15 '19 13:06 zckevin