您好,欢迎来到世娱网。
搜索
您的当前位置:首页vue 中使用 watch 出现了如下的报错的原因分析

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

来源:世娱网


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

Copyright © 2019- worldimage.cn 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务