var app = getApp(); Page({ data:{ txtInit: "" , tIndex: null , txt: "" , borderWidth: app.globalData.borderWidth, }, gettxt: function (e){ // console.log(e.detail.value); let that = this ; let txts = e.detail.value.replace(//s+/g, " " ); wx.setStorageSync( 'temptxt' , txts); that.setData({ txt: txts }); }, confirmtxt: function (){ // let that = this; // if(wx.getStorageSync('temptxt') != ""){ // }; // var temptxt = that.data.txt || that.data.txtInit; // console.log(temptxt); // let txtObjStr = JSON.stringify({ t_index: that.data.tIndex, cnt: that.data.txt }); // console.log(JSON.stringify({ t_index: that.data.tIndex, cnt: that.data.txt })) // if(temptxt != " " && temptxt != ""){ // console.log(temptxt); // wx.setStorage({ // key: 'temptxt', // data: { t_index: that.data.tIndex, cnt: that.data.txt }, // }); // if(that.data.tIndex != undefined){ // wx.setStorageSync('temptxt', txtObjStr); // }else{ // wx.setStorageSync('temptxt', {t_index: that.data.tIndex, cnt: that.data.txt}); // } wx.switchTab({ url: '../index/index' , success: function (res){ // success }, fail: function (res) { // fail app.warn( "跳轉(zhuǎn)失敗" ); } }) // }else{ // app.warn("你并未輸入有效文字信息!"); // }; }, onLoad: function (options){ // 生命周期函數(shù)--監(jiān)聽頁面加載 // console.log(options); wx.setStorageSync( 'temptxt' , "" ); wx.setStorageSync( 'tIndex' , options.tIndex); console.log(options.txt); console.log(options.tIndex); if (options.txt != "undefined" && options.tIndex !== "undefined" ){ this .setData({ tIndex: options.tIndex, txtInit: options.txt, }) } }, }) |
網(wǎng)友回復:
請問是哪個版本?
微信web開發(fā)者工具 v0.17.170900
在上周及之前時代碼還是好用的(當時用的是注釋掉的代碼),真機也是正常的,沒有出現(xiàn)過storage的問題。這周一來,真機和模擬器都出問題了,各種改也沒用,其他頁面存儲沒問題,只有在這個編輯文本的界面存和跳轉(zhuǎn)后發(fā)生了這情況,發(fā)的代碼就是這個編輯文本界面的代碼
找到了,問題在跳轉(zhuǎn)頁面的 wx.clearStorageSync("temptxt"); clear全清空,應該用remove,都忘了什么時候的代碼了,這種錯誤...但是為什么之前沒問題。。。是我的問題