search
HomeWeChat AppletMini Program DevelopmentHow 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 == &#39;&#39; ){ 
 wx.showToast({ 
 title: &#39;请先输入解密密码&#39;, 
 mask: true, 
 success: function (res) { 
  setTimeout(function () { 
  wx.hideToast(); 
  }, 4000); 
 }, 
 }); 
 return; 
 }else{ 
 wx.getClipboardData({ 
 <strong>success: function (res)</strong> { 
  if ( res.data == &#39;&#39; ){ 
  wx.showToast({ 
  title: &#39;剪贴板没有内容&#39;, 
  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 == &#39;&#39; ){ 
 wx.showToast({ 
 title: &#39;请先输入解密密码&#39;, 
 mask: true, 
 success: function (res) { 
 setTimeout(function () { 
 wx.hideToast(); 
 }, 4000); 
 }, 
 }); 
 return; 
}else{ 
 wx.getClipboardData({ 
 success: function (res) { 
 if ( res.data == &#39;&#39; ){ 
 wx.showToast({ 
  title: &#39;剪贴板没有内容&#39;, 
  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 that the WeChat mini program cannot request data when requesting the server mobile phone preview

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

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

SublimeText3 English version

Recommended: Win version, supports code prompts!