久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

解決Vue中的生命周期beforeDestory不觸發的問題

瀏覽:109日期:2023-01-01 11:51:37

分享一句很有用的經驗:

給router-view加了個keep-alive導致組件緩存了,所以不會觸發beforeDestory和destoryed

結束!

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

場景

. SPA中 使用vuex初始化一項數據,在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后的變量調用 $http

解決

. 聲明Vue實列的常量 并且依靠這個常量調用$http

const Http = new Vueactions : { 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不觸發的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 莱芜市| 南和县| 吴旗县| 于田县| 左贡县| 扎赉特旗| 水城县| 东安县| 西乌珠穆沁旗| 邢台市| 林芝县| 定襄县| 周口市| 秭归县| 勃利县| 衡东县| 安溪县| 北安市| 莫力| 佛教| 肥城市| 金华市| 积石山| 大连市| 瑞丽市| 遂平县| 会理县| 泗洪县| 湄潭县| 大姚县| 高陵县| 甘孜| 九寨沟县| 施甸县| 漯河市| 彭泽县| 鹰潭市| 凤庆县| 溧阳市| 商城县| 临沭县|