失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 如何解决微信小程序报错:this.setData is not a function的问题

如何解决微信小程序报错:this.setData is not a function的问题

时间:2019-07-25 05:45:39

相关推荐

如何解决微信小程序报错:this.setData is not a function的问题

微信小程序|小程序开发

微信小程序报错:this.setData,is,not,a,function,小程序报错解决办法

微信小程序-小程序开发微信小程序 报错:this.setData is not a function

易经起名源码,Ubuntu访问电脑文件,如何清理tomcat项目缓存,梨视频爬虫,php psr下载,太原seo优化网络营销哪家好lzw

在page中定义的代码如下,代码会报错:this.setData is not a function

1号店 源码,vscode修改pdf,ubuntu怎么测试鼠标失灵,修改完tomcat,读取sqlite指定行,原生js 轮播插件,前端框架在线搭建,爬虫温度发热线,php mysql支持,seo实训教程,水果公司网站源码,易语言网页游戏句柄,html5管理网站免费模板,wordpress制作404页面模板,基于ssh的图书管理系统源码下载,微信小程序源码 资源网lzw

pasteEncryptedText:function(){ let decryptedPass = this.data.decryptedPassword; 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);this.setData({ encryptedTextDecode: res.data, originalTextDecode: desEncryptedDecrypted.decrypt(res.data, decryptedPass), });console.log(this.data.originalTextDecode); } } }); } }

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

django blog 源码下载,怎么在vscode上打开cmd,主机是ubuntu,tomcat较好的书籍,爬虫股票算法,php常见框架,seo优化中下拉优化的好处lzw

中的this不是page,而是wx.showToast这个对象了

解决方法:

在函数pasteEncryptedText()一开始处将this对象保存:let that = this;

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

let that = this;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);that.setData({ encryptedTextDecode: res.data, originalTextDecode: desEncryptedDecrypted.decrypt(res.data, decryptedPass), }); console.log(that.data.originalTextDecode); } } }); }

如果觉得《如何解决微信小程序报错:this.setData is not a function的问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。