


How to solve the problem of WeChat applet error: this.setData is not a function
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!
