Error in Created hook: 'TypeError's: Cannot read property 'num' of 'undefined'

目录
Uni-App编写组件的时候,生命周期函数时遇到了使用箭头函数拿不到this的Vue对象的情况
代码
报错
浏览器控制台报下面的错误
|
|
原因
箭头函数和普通函数是有区别的,,因为箭头凶数并没有this , this会作为变量一直向上级词法作用域查找,直至找到为止,经常导致Uncaught TypeError: Cannot read property of undefined
或Uncaught TypeError : this.myMethod is not a function
之类的错误。
解决
用普通函数替换箭头函数就行了