小程序报错:这。setData不是一个函数的解决方法

  介绍

这篇文章主要介绍小程序报错:这个。setData不是一个函数的解决方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

微信小程序报错:这个。setData不是一个函数

在页面中定义的代码如下,代码会报错:这个。setData不是一个函数

& lt; strong>, pasteEncryptedText:函数()& lt;/strong> {,   ,let  decryptedPass =, this.data.decryptedPassword;,   ,if  (decryptedPass ==, & # 39; & # 39;,) {,   wx.showToast({大敌;   标题:大敌;& # 39;请先输入解密密码& # 39;,,   ,面具:真的,,   ,成功:function  (res), {,   setTimeout(才能function  (), {,   wx.hideToast才能(),,   ,,},4000);,   },大敌;   ,});   ,返回;   其他}{大敌;   wx.getClipboardData({大敌;   ,& lt; strong>成功:function  (res) & lt;/strong>, {,   if 才能;(==,,res.data  & # 39; & # 39;,) {,   ,wx.showToast({大敌;   ,,标题:& # 39;剪贴板没有内容& # 39;,,   面具:才能,真的,,   ,,成功:function  (res), {,   setTimeout(才能function  (), {,   ,,wx.hideToast (),,   ,,},4000);,   ,,},   }),才能   其他,}{大敌;   console.log才能(decryptedPass);,   console.log才能(res.data);,   & lt;才能strong> this.setData ({,   ,,encryptedTextDecode: res.data,,   ,,originalTextDecode: desEncryptedDecrypted.decrypt (decryptedPass res.data也),   });才能& lt;/strong>,   console.log才能(this.data.originalTextDecode);,   ,,},   }大敌;   ,});   }大敌;   以前,}

<强>问题分析:在函数pasteEncryptedText()里面嵌套调用另一个函数wx.showToast(),而setData()是在wx.showToast()中调用的,此时this.setData (),

中的这个不是页面,而是wx。showToast()这个对象了

<强>解决方法:

& lt; strong>,在函数pasteEncryptedText()一开始处将这对象保存:& lt;/strong> let  that =,, pasteEncryptedText:函数(){,   ,let  decryptedPass =, this.data.decryptedPassword; & lt; strong> let  that =,, & lt;/strong>,   if  (decryptedPass ==, & # 39; & # 39;,) {,   wx.showToast({大敌;   标题:大敌;& # 39;请先输入解密密码& # 39;,,   ,面具:真的,,   ,成功:function  (res), {,   ,setTimeout (function  (), {,   ,wx.hideToast (),,   ,},4000);,   },大敌;   ,});   ,返回;   }{,其他   wx.getClipboardData({大敌;   ,成功:function  (res), {,   ,if  (==,, res.data  & # 39; & # 39;,) {,   wx.showToast({大敌;   ,,标题:& # 39;剪贴板没有内容& # 39;,,   面具:才能,真的,,   ,,成功:function  (res), {,   setTimeout(才能function  (), {,   wx.hideToast才能(),,   ,,},4000);,   ,,},   })大敌;   其他}{大敌;   ,console.log (decryptedPass);,   ,console.log (res.data);,   ,& lt; strong> that.setData ({,   ,,encryptedTextDecode: res.data,,   ,,originalTextDecode: desEncryptedDecrypted.decrypt (decryptedPass res.data也),   ,});   ,console.log (& lt; strong> that.data.originalTextDecode</strong>),,   }大敌;   }大敌;   ,});   }

以上是“小程序报错:这个。setData不是一个函数的解决方法”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

小程序报错:这。setData不是一个函数的解决方法