报错: Method "watch" has type "object" in the component definition. Did you reference the function Method "watch" has type "object" in the component definition. Did you reference the function correctly?

  原因: watch 是一个对象,应该以键值对的形式来使用,但是我 将 watch 放到了 methods: {} 中,导致了这个问题;

  解决办法:  将watch 对象 拿出来,与 methods 平级;

 

附上当时的代码:

watch: {
        "$route.path":function(newval){
          if(newval === '/home'){
            this.flag = false
          }else{
            this.flag = true
          }
        }
      }
  }
在 vue 组件的函数里面调用 定时器 setTimeout(function(){},1000) 和 setInterval(fucntiong(){},1000) 时, 必须使用箭头函数, 因为定时器函数里面的 this 指向的是 window , 从而导致在 函数里面 用 this 调用 data  里面的数据时失败,无法获取; 

相关文章:

  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
猜你喜欢
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案