zoukankan      html  css  js  c++  java
  • vue watch监听路由变化

    vue watch监听路由变化

    // 监听 this.$route.path 
    // watch监听非DOM元素的改变
    watch:{
     '$route.path':function(to,from){
        console.log(to);
      }
    },
    
    // 监听,当路由发生变化的时候执行
    watch:{
      $route(to,from){
        console.log(to.path);
      }
    },
    或者
    // 监听,当路由发生变化的时候执行
    watch: {
      $route: {
        handler: function(val, oldVal){
          console.log(val);
        },
        // 深度观察监听
        deep: true
      }
    },
    或者
    // 监听,当路由发生变化的时候执行
    watch: {
      '$route':'getPath'
    },
    methods: {
      getPath(){
        console.log(this.$route.path);
      }
    }
    
    
  • 相关阅读:
    Matrix
    Color the ball
    Coupons
    密码箱
    Milking Grid
    Substrings
    亲和串
    Jzzhu and Cities
    transition多个属性同时渐变(left/top)
    CSS3提供的transition动画
  • 原文地址:https://www.cnblogs.com/niuben/p/14890233.html
Copyright © 2011-2022 走看看