TypeError: Cannot read property ‘username’ of undefined
最近在uni-app开发安卓app的项目中用到onLoad()生命周期中,需要改变username的值,但是频频报错:TypeError: Cannot read property ‘username’ of undefined
后面才发现是箭头函数this的指向问题,一开始生命周期使用箭头函数封装了:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bb5a752269195ad5aef175e9b58b4851.png)
导致this一直指向undefined,这可能是因为箭头函数对this的指向严格限制,后面还是改回来,就可以了;
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/82874e253e6fbee8137653486226124d.png)