码迷,mamicode.com
首页 > 其他好文 > 详细

vue箭头函数注意事项

时间:2018-07-16 14:11:24      阅读:946      评论:0      收藏:0      [点我收藏+]

标签:efi   undefined   箭头   选项   java   javascrip   target   method   href   

不要在选项属性或回调上使用箭头函数

比如 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 之类的错误。

vue箭头函数注意事项

标签:efi   undefined   箭头   选项   java   javascrip   target   method   href   

原文地址:https://www.cnblogs.com/z5-26/p/9317008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!