博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php isnotset,如何解决微信小程序报错:this.setData is not a function的问题
阅读量:7085 次
发布时间:2019-06-28

本文共 1823 字,大约阅读时间需要 6 分钟。

这篇文章主要介绍了微信小程序报错:this.setData is not a function的解决办法的相关资料,希望通过本文能帮助到大家解决这样类似的问题,需要的朋友可以参考下

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

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

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()

中的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);

}

}

});

}

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

转载地址:http://xarml.baihongyu.com/

你可能感兴趣的文章
键盘回车登录的做法
查看>>
优雅的使用python之环境管理
查看>>
取出当前脚本所在位置、文件名
查看>>
【转】每天一个linux命令(14):head 命令
查看>>
Careerdesign@foxmail.com
查看>>
mkdir failed for img Read-only file system
查看>>
写在2015年即将来临之际
查看>>
【UVA】434-Matty's Blocks
查看>>
MyISAM和InnoDB的区别
查看>>
boost.lexical_cast 学习
查看>>
Android中使用第三方jar包
查看>>
应用程序框架实战三十:表现层及ASP.NET MVC介绍(一)
查看>>
后端码农谈前端(HTML篇)第三课:常见属性
查看>>
NPOI系列
查看>>
virtual private catalog
查看>>
Android剪裁图片简单的方法
查看>>
iPhone/Mac Objective-C内存管理教程和原理剖析
查看>>
PRML Chapter 2. Probability Distributions
查看>>
[转]Console命令详解,让调试js代码变得更简单
查看>>
dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
查看>>