vue箭头函数问题

不要在选项属性或回调上使用箭头函数,比如created: () => console.log(this.a) 或vm.$watch('a', newValue => this.myMethod())。因为箭头函数是和父级上下文绑定在一起的,this 不会是如你所预期的 Vue 实例,经常导致Uncaught TypeError: Cannot read property of undefined 或Uncaught TypeError: this.myMethod is not a function 之类的错误。

posted @ 2018-03-19 10:23  张正-博客园  阅读(225)  评论(0编辑  收藏  举报