How to solve the problem of WeChat Mini Programs reporting an error in this.setData is not a function
This article mainly introduces "WeChat Mini Programs reported wrong this.setData is not a function how to solve". In daily operation, I believe that many people have doubts about how WeChat Mini Programs reported wrong this.setData is not a function how to solve the problem. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "WeChat Mini Programs reported wrong this.setData is not a function how to solve". Next, please follow the editor to study!
WeChat Mini Programs reported an error: this.setData is not a function
The code defined in page is as follows, and the code will report an error: this.setData is not a function
PasteEncryptedText:function () {let decryptedPass = this.data.decryptedPassword; if (decryptedPass = ='') {wx.showToast ({title: 'please enter the decryption password first', mask: true, success: function (res) {setTimeout (function () {wx.hideToast ();}, 4000);},}); return } else {wx.getClipboardData ({success: function (res) {if (res.data = ='') {wx.showToast ({title: 'clipboard has no content', mask: true, success: function (res) {setTimeout (function () {wx.hideToast ();}, 4000);},})} else {console.log (decryptedPass); console.log (res.data) This.setData ({encryptedTextDecode: res.data, originalTextDecode: desEncryptedDecrypted.decrypt (res.data, decryptedPass),}); console.log (this.data.originalTextDecode);};}
Problem analysis: another function wx.showToast () is nested in the function pasteEncryptedText (), while setData () is called in wx.showToast (), when this.setData ()
The this in is not page, but the object wx.showToast ()
Solution:
Save the this object at the beginning of the function pasteEncryptedText (): let that = this;pasteEncryptedText:function () {let decryptedPass = this.data.decryptedPassword;let that = this; if (decryptedPass = =') {wx.showToast ({title: 'please enter the decryption password first', mask: true, success: function (res) {setTimeout (function () {wx.hideToast ();}, 4000);},},}); return } else {wx.getClipboardData ({success: function (res) {if (res.data = ='') {wx.showToast ({title: 'clipboard has no content', mask: true, success: function (res) {setTimeout (function () {wx.hideToast ();}, 4000);},})} else {console.log (decryptedPass); console.log (res.data) That.setData ({encryptedTextDecode: res.data, originalTextDecode: desEncryptedDecrypted.decrypt (res.data, decryptedPass),}); console.log (that.data.originalTextDecode);});} at this point, the study on "how to solve WeChat Mini Programs's error this.setData is not a function" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!