您的位置:首页 > Web前端 > Vue.js

vue 中使用 watch 出现了如下的报错的原因分析

2019-05-21 08:35 483 查看

报错: 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 中使用 watch 出现了如下的报错的原因分析,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vue watch 报错
相关文章推荐