vue进入页面每次都调用methods里的方法

// 监听路由,每次进入页面调用方法,放在method里
mounted(){
  this.getPath()
},
methods: {
  getPath(){
    console.log(this.$route.path);
    if (this.$route.path == '你要进入的路由') {
    this.init() // 初始化的方法
    }
  }
},
watch: {
   '$route':'getPath'
},

  

原文地址:https://www.cnblogs.com/henuyuxiang/p/14918445.html