Vue2.0 探索之路——vue-router入門教程和總結

今天在實現一個小功能的時候,遇到一個問題,使用vue-router獲取上一頁面的url信息,我嘗試了多種方式,發現使用vue-router的canDeactivate鉤子實現這個功能最爲方便,現在將我的實現代碼總結如下:

           項目使用的是vue-cli,直接貼代碼         

複製代碼
export default {
    mixins: [],
    vuex: {
      actions: {fetchCertificates},
    },
    data() {
      return {}
    },
    route: {
      data() {
        this.$root.showLoading();
        return this.fetchCertificates().then((res) => {
          this.$root.dismissLoading();
          if (res.error) return this.$root.toastError(res.error);
          if(res.data.certificates.length >0){
            return res.data;
          }else{
            console.log(this.$route ,"----當前頁面的url信息----");
          }
        });
      },
      canActivate (transition) {
        console.log(transition,"======上一個頁面的url信息=======");
        transition.next();
      }
    },
  }
複製代碼

 

      

轉載http://www.cnblogs.com/chenyablog/p/6951530.html
發佈了1 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章