微信小程序|小程序开发
微信小程序报错: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); } } }); }