微信小程序报错:this.setData is not a function的解决
网络编程 2021-07-04 17:32www.168986.cn编程入门
这篇文章主要介绍了微信小程序报错:this.setData is not a function的解决办法的相关资料,希望通过本文能帮助到大家解决这样类似的问题,需要的朋友可以参考下
微信小程序 报错:this.setData is not a function
在page中定义的代码如下,代码会报错:this.setData is not a function
<strong> pasteEncryptedText:function()</strong>{ let decryptedPass = this.data.decryptedPassword; if (decryptedPass == '' ){ wx.showToast({ title: '请先输入解密密码', mask: true, suess: function (res) { setTimeout(function () { wx.hideToast(); }, 4000); }, }); return; }else{ wx.getClipboardData({ <strong>suess: function (res)</strong> { if ( res.data == '' ){ wx.showToast({ title: '剪贴板没有内容', mask: true, suess: 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); } } }); } }
问题分析:在函数 pasteEncryptedText()里面嵌套调用另一个函数 wx.showToast(),而setData()是在wx.showToast()中调用的,此时this.setData()
中的this不是page,而是wx.showToast()这个对象了
解决方法:
<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, suess: function (res) { setTimeout(function () { wx.hideToast(); }, 4000); }, }); return; }else{ wx.getClipboardData({ suess: function (res) { if ( res.data == '' ){ wx.showToast({ title: '剪贴板没有内容', mask: true, suess: 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>); } } }); }
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望通过本文能帮助到大家,谢谢大家对本站的支持!
上一篇:js移动端图片压缩上传功能
下一篇:EasyUI Tree树组件无限循环的解决方法
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程