Back

vuejs - 点击页面,刷新当前页面的时候, 要使用watch,否则当前页面不会自动刷新

发布时间: 2019-01-01 09:15:00

参考: https://router.vuejs.org/guide/advanced/data-fetching.html#fetching-after-navigationhttps://github.com/vuejs/vue-router/issues/1012

如题。要使用watch 

export default {
  data () {
    return {
       ....
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    truncate: truncate,
    fetchData: function () {
      Vue.http.get(url).then((response ) => {
      }, (response) => {
        console.error(response)
      })
    },
    go: function (vid){
      this.$router.push({name: 'ShowVideo', params: { vid: vid}})
    }
  },
  watch: {
    "$route": 'fetchData'    // 要watch route , 一旦发生变化,就调用 fetchData方法
  }
}

Back