|
導讀微信小程序,簡稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應用,它實現了應用“觸手可及”的夢想,用戶掃一掃或搜一下即可打開應用。小程序是一種不用下載就能使用的應用,也是一... 微信小程序,簡稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應用,它實現了應用“觸手可及”的夢想,用戶掃一掃或搜一下即可打開應用。小程序是一種不用下載就能使用的應用,也是一項門檻非常高的創新,經過將近兩年的發展,已經構造了新的小程序開發環境和開發者生態。 這篇文章主要介紹了微信小程序報錯:this.setData is not a function的解決辦法的相關資料,希望通過本文能幫助到大家解決這樣類似的問題,需要的朋友可以參考下微信小程序 報錯: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>);
}
}
});
}以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網! 相關推薦: 如何解決微信公眾號 提示:Unauthorized API function的問題 如何解決微信小程序中出現的錯誤:{"baseresponse":{"errcode":-80002,"errmsg":""}} 以上就是如何解決微信小程序報錯:this.setData is not a function的問題的詳細內容,更多請關注php中文網其它相關文章! 小程序是一種不需要下載安裝即可使用的應用,它實現了應用“觸手可及”的夢想,用戶掃一掃或者搜一下即可打開應用。 |
溫馨提示:喜歡本站的話,請收藏一下本站!