0
点赞
收藏
分享

微信扫一扫

nuxt.js中如何使用watch监听路由

西街小学的王 2022-02-28 阅读 140

```javascript
watch: {
    $route: {
      immediate: true,    //加上此配置之后,watch即可以在首次进入或刷新之后执行handler (),即初始化即可执行监听
      handler (to, from) {  //监听之后执行的回调
        if (to.path === '/login-pc' && this.allConfig.enable_login !== '1') {    //判断条件
          this.$router.push('/pc')
        }
        if (
          to.path === '/pc/register' &&
          this.allConfig.enable_register !== '1'
        ) {
          this.$router.push('/pc')
        }
      }
    }
  },

**总结:nuxt.js中其实和vue中的watch监听路由是一样的。没什么区别。**
举报

相关推荐

Nuxt.js

nuxt.js使用scss

Nuxt.js 使用sass

Nuxt.js学习

Nuxt.js 整合 ElementUI

【操作】Nuxt.js安装

0 条评论