国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

vue中全局路由守衛中替代this操作(this.$store/this.$vux)

瀏覽:92日期:2022-12-29 11:21:15

全局路由守衛this.$vux.loading.hide()報錯,訪問不到this

解決辦法

申明變量代替this

main.js文件方法

router.beforeEach((to, from, next) => { if(vue){ vue.$vux.loading.hide() }else{ } next()})let vue = new Vue({ el: ’#app’, router, store, components: { App }, template: ’<App/>’})

if判斷防止第一次初始化報錯

或者

let vue = new Vue({ el: ’#app’, router, store, components: { App }, template: ’<App/>’})router.beforeEach((to, from, next) => { // if(vue){ vue.$vux.loading.hide() // }else{ // } next()})

補充知識:解決導航守衛使用不了this.$store

在vue router的導航守衛如beforeEach()中是無法直接通過this.$store去操作vuex的,因為這里的this指向不一致。

解決方式是在router的index.js中引入初始化好的store

import store from ’@/store’

然后在導航守衛中可直接拿到router了

/**導航守衛 */router.beforeEach((to, form, next) => { console.log(store.getters)})

以上這篇vue中全局路由守衛中替代this操作(this.$store/this.$vux)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 大田县| 泰来县| 会泽县| 南宁市| 延边| 同仁县| 壤塘县| 鸡东县| 清丰县| 沿河| 个旧市| 贵德县| 铜鼓县| 阿图什市| 营山县| 灵武市| 宾川县| 龙海市| 玛沁县| 淮阳县| 乡城县| 安义县| 大丰市| 玉溪市| 留坝县| 淮南市| 尼玛县| 潞城市| 绥滨县| 两当县| 威海市| 田阳县| 亳州市| 芦溪县| 游戏| 靖西县| 龙里县| 青神县| 旬邑县| 临沭县| 九台市|