In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
The main content of this article is to explain "how to solve the error report this.setData in WeChat Mini Programs". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let's let the editor take you to learn "how to solve the problem of error reporting this.setData in WeChat Mini Programs".
Let's start with the reasons:
The scope of the function declared by function is different from that of the arrow function, which is an accidental pit.
So for this result, it's best to go back to es5's function function to write it.
The difference between the arrow function and function:
The this object in the arrowhead function is the object in which it is defined, not the object in which it is used.
The arrow function cannot be treated as a constructor, that is, you cannot use the new command, or an error will be thrown
The arrow function cannot use an arguments object, which does not exist in the body of the function. If you want to use it, you can use the Rest parameter instead of the yield command, so the arrow function cannot be used as a Generator function.
If you write in this way, you will report an error.
ThirdScriptErrorthis.setData is not a function;at pages/index/index onLoad function;at api getSystemInfo success callback functionTypeError: this.setData is not a functiononLoad: function () {wx.getSystemInfo ({success: function (res) {this.setData ({lang: res.language}) console.log (res.language)})
If you change it in this way, you won't make a mistake.
OnLoad: function () {wx.getSystemInfo ({success: (res) = > {this.setData (the this of the {arrow function always points to this lang: res.language}) console.log (res.language)}} when the function is defined)
Or this:
OnLoad: function () {var that=this; wx.getSystemInfo ({success: function (res) {that.setData ({lang: res.language}) console.log (res.language)}})
You can use the following example to illustrate:
'use strict';var obj = {I: 10, b: () = > console.log (this.i, this), c: function () {console.log (this.i, this);}} obj.b (); / / prints undefined, Window {.} (or the global object) obj.c () / / prints 10, Object {.} at this point, I believe you have a deeper understanding of "how to solve the problem of error reported by WeChat Mini Programs". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.