国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序報錯:this.setData is not a function的解決辦法

2024-07-22 01:17:20
字體:
供稿:網(wǎng)友

微信小程序 報錯: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,  success: function (res) {   setTimeout(function () {   wx.hideToast();   }, 4000);  },  });  return;  }else{  wx.getClipboardData({  <strong>success: function (res)</strong> {   if ( res.data == '' ){   wx.showToast({   title: '剪貼板沒有內(nèi)容',   mask: true,   success: 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);   }  }  });  }  } 

問題分析:在函數(shù) pasteEncryptedText()里面嵌套調(diào)用另一個函數(shù) wx.showToast(),而setData()是在wx.showToast()中調(diào)用的,此時this.setData() 

中的this不是page,而是wx.showToast()這個對象了 

解決方法:

<strong> 在函數(shù)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,  success: function (res) {  setTimeout(function () {  wx.hideToast();  }, 4000);  },  });  return; }else{  wx.getClipboardData({  success: function (res) {  if ( res.data == '' ){  wx.showToast({   title: '剪貼板沒有內(nèi)容',   mask: true,   success: 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>);  }  }  }); } 

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望通過本文能幫助到大家,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 台湾省| 竹北市| 余江县| 武隆县| 汝南县| 宜兰市| 汝城县| 巫溪县| 通山县| 周口市| 龙井市| 温州市| 武邑县| 共和县| 望城县| 北川| 桑日县| 满城县| 肇庆市| 岑巩县| 平顺县| 将乐县| 浦县| 泸西县| 黄龙县| 汨罗市| 石门县| 营口市| 囊谦县| 洛隆县| 临颍县| 通榆县| 华池县| 滦南县| 那曲县| 盘山县| 额敏县| 红原县| 苍溪县| 资兴市| 苍溪县|