This article mainly introduces the relevant information about the solution to the WeChat applet error: this.setData is not a function. I hope this article can help everyone solve similar problems. Friends in need can refer to it
WeChat applet reports an error: this.setData is not a function
The code defined in the page is as follows, the code will report an error: this.setData is not a function
<strong> pasteEncryptedText:function()</strong>{ let decryptedPass = this.data.decryptedPassword; if (decryptedPass == '' ){ wx.showToast({ title: '请先输入解密密码', mask: true, success: function (res) { setTimeout(function () { wx.hideToast(); }, 4000); }, }); return; }else{ wx.getClipboardData({ <strong>success: function (res)</strong> { if ( res.data == '' ){ wx.showToast({ title: '剪贴板没有内容', mask: true, success: function (res) { setTimeout(function () { wx.hideToast(); }, 4000); }, }) }else{ console.log(decryptedPass); console.log(res.data); <strong>this.setData({ encryptedTextDecode: res.data, originalTextDecode: desEncryptedDecrypted.decrypt(res.data, decryptedPass), });</strong> console.log(this.data.originalTextDecode); } } }); } }
Problem analysis: Call another function wx.showToast() nested inside the function pasteEncryptedText(), and setData () is called in wx.showToast(). At this time, this.setData()
this is not the page, but the object wx.showToast()
Solution:
<strong> 在函数pasteEncryptedText()一开始处将this对象保存:</strong>let that = this;
pasteEncryptedText:function(){ let decryptedPass = this.data.decryptedPassword;
<strong>let that = this;</strong> if (decryptedPass == '' ){ wx.showToast({ title: '请先输入解密密码', mask: true, success: function (res) { setTimeout(function () { wx.hideToast(); }, 4000); }, }); return; }else{ wx.getClipboardData({ success: function (res) { if ( res.data == '' ){ wx.showToast({ title: '剪贴板没有内容', mask: true, success: function (res) { setTimeout(function () { wx.hideToast(); }, 4000); }, }) }else{ console.log(decryptedPass); console.log(res.data); <strong> that.setData</strong>({ encryptedTextDecode: res.data, originalTextDecode: desEncryptedDecrypted.decrypt(res.data, decryptedPass), }); console.log(<strong>that.data.originalTextDecode</strong>); } } }); }
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to solve the problem WeChat public account prompt: Unauthorized API function problem
#How to solve the error in the WeChat applet: {"baseresponse":{"errcode":-80002,"errmsg ":""}}
The above is the detailed content of How to solve the problem of WeChat applet error: this.setData is not a function. For more information, please follow other related articles on the PHP Chinese website!