vuejs / vue-hackernews-2.0

HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
MIT License
10.96k stars 2.15k forks source link

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

Open buptsb opened 5 years ago

buptsb commented 5 years ago

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!