亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決Vue中的生命周期beforeDestory不觸發(fā)的問題

 更新時間:2020年07月21日 11:52:56   作者:Various  
這篇文章主要介紹了解決Vue中的生命周期beforeDestory不觸發(fā)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

分享一句很有用的經(jīng)驗:

給router-view加了個keep-alive導(dǎo)致組件緩存了,所以不會觸發(fā)beforeDestory和destoryed

結(jié)束!

補充知識:vuex actions正確使用vue-resource的方式( Error in mounted hook: "TypeError: Cannot read property 'get' of u)

場景

. SPA中 使用vuex初始化一項數(shù)據(jù),在vuex的actions中需要使用vue-resource

使用的方式是

actions : {
 setTaskList : function (store) {
  let url = 'http://zhihu.carsonlius_liu.cn/api/tasks';
  Vue.$http.get(url).then(function (response) {
   if (response.status === 200) {
    store.commit('setTask', response.body);
   }
  });
 }
}

報錯提示

Error in mounted hook: "TypeError: Cannot read property 'get' of undefined

分析

. 提示Vue.$http.get 是不存在;打印之后果然不存在, 所以問題就是Vue.上面了

. 在actions里面打印 console.log(Vue);

`warn('Vue is a constructor and should be called with the `new` keyword');`

. 所以嘗試實例化Vue后的變量調(diào)用 $http

解決

. 聲明Vue實列的常量 并且依靠這個常量調(diào)用$http

const Http = new Vue
actions : {
  setTaskList : function (store) {
   let url = 'http://zhihu.carsonlius_liu.cn/api/tasks';
   Http.$http.get(url).then(function (response) {
    if (response.status === 200) {
     store.commit('setTask', response.body);
    }
   });
  }
}

以上這篇解決Vue中的生命周期beforeDestory不觸發(fā)的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論