设为首页 加入收藏

TOP

vue 中使用 watch 的各种问题
2019-09-17 18:47:31 】 浏览:22
Tags: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 组件的函数里面调用 定时器 setTimeout(function(){},1000) 和 setInterval(fucntiong(){},1000) 时, 必须使用箭头函数, 因为定时器函数里面的 this 指向的是 window , 从而导致在 函数里面 用 this 调用 data  里面的数据时失败,无法获取; 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ES6 入门系列 (一)ES6的前世今生 下一篇vue+element打印页面功能

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目