_独钓寒江雪

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 报错: 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  里面的数据时失败,无法获取; 

posted on 2019-05-20 21:54  _独钓寒江雪  阅读(7439)  评论(0编辑  收藏  举报