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

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 15:16:59
字體:
來源:轉載
供稿:網友

微信小程序 報錯: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: '剪貼板沒有內容',   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);   }  }  });  }  } 

問題分析:在函數 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,  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);  <strong> that.setData</strong>({   encryptedTextDecode: res.data,   originalTextDecode: desEncryptedDecrypted.decrypt(res.data, decryptedPass),  });  console.log(<strong>that.data.originalTextDecode</strong>);  }  }  }); } 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富源县| 福贡县| 宝应县| 九台市| 滦南县| 平和县| 崇义县| 扬州市| 永德县| 丰县| 柏乡县| 建阳市| 康定县| 赤峰市| 神农架林区| 德化县| 邵东县| 道孚县| 宜阳县| 鹤峰县| 库尔勒市| 海兴县| 东山县| 廊坊市| 岱山县| 白山市| 永兴县| 博白县| 五家渠市| 横峰县| 湾仔区| 水城县| 泽库县| 汽车| 昌都县| 福鼎市| 德清县| 望城县| 罗平县| 汉源县| 修武县|