How to solve the problem of WeChat applet error: this.setData is not a function

不言
Release: 2018-06-27 16:15:07
Original
2841 people have browsed it

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); 
  } 
 } 
 }); 
 } 
 }
Copy after login

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;
Copy after login

pasteEncryptedText:function(){ 
 let decryptedPass = this.data.decryptedPassword;
Copy after login

<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>); 
 } 
 } 
 }); 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template