(刷新数据 )vue中通过this.$router.push 到当前页面,只是参数不同,页面没有重新请求数据?

//vue-router 官方demo 好像也不行
export default {
  data () {
    return {
      loading: false,
      post: null,
      error: null
    }
  },
  created () {
    // fetch the data when the view is created and the data is
    // already being observed
    this.fetchData()
  },
  watch: {
    // call again the method if the route changes
    '$route': 'fetchData'
  },
  methods: {
    fetchData () {
      this.error = this.post = null
      this.loading = true
      // replace getPost with your data fetching util / API wrapper
      getPost(this.$route.params.id, (err, post) => {
        this.loading = false
        if (err) {
          this.error = err.toString()
        } else {
          this.post = post
        }
      })
    }
  }
}

 

posted @ 2020-04-02 10:26  ThisCall  阅读(3129)  评论(0编辑  收藏  举报