当前位置: 移动技术网 > IT编程>开发语言>JavaScript > vue 中使用 watch 出现了如下的报错

vue 中使用 watch 出现了如下的报错

2019年05月21日  | 移动技术网IT编程  | 我要评论

 报错: 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
          }
        }
      }
  }

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网