欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序如何修改本地緩存key中單個數(shù)據(jù)的詳解

 更新時間:2019年04月26日 10:46:45   作者:lff1123  
這篇文章主要介紹了微信小程序如何修改本地緩存key中單個數(shù)據(jù),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

最近在做教師評教系統(tǒng),有一個‘個人信息'頁面中有個編輯修改郵箱的功能,本來想得很簡單,結(jié)果進坑了,搞了好久才出來。

我想實現(xiàn)的效果是點擊下圖左側(cè)郵箱,然后進入右側(cè)頁面,進行郵箱的修改,點擊提交后跳轉(zhuǎn)到左側(cè)頁面,同時郵箱也發(fā)生改變。

點擊‘我的'時,我讓它從控制臺打印出student緩存中傳過來的數(shù)據(jù),如下:

{no: "1635050601", name: "張三", sex: "", email: "123@qq.com", classid: "100000-1602", …}
classid:"100000-1602"
classname:"16級PHP2"
departmentid:"100000"
departmentname:"軟件學院"
name:"張三"
no:"1635050601"
sex:""

然后我添加郵箱后,后臺接口寫了方法讓email的值直接存到student中,但是如果初次添加email的話可以實現(xiàn),第二次修改email的話,就得想想該怎么從student里只修改email的值。

 //表單提交
 formSubmit: function (e) {
 console.log(e.detail.value);
 var pwd = e.detail.value.pwd;
 var email = e.detail.value.email;
 if (pwd == '') {
  wx.showToast({
  title: '密碼不能為空',
  icon: 'none',
  duration: 1000,
  })
 }else if (email == '') {
  wx.showToast({
  title: '郵箱不能為空',
  icon: 'none',
  duration: 1000,
  })
 }else {
  //post方式提交
  wx.request({
  url: app.globalData.url.bindemail,
  method: "POST",
  data: {
   no: this.data.no,
   pwd: pwd,
   email: email
  },
  header: {
   "Content-Type": "application/x-www-form-urlencoded"
  },
  success: function (res) {
   // console.log(res);
   if(res.data.error == true){
   wx.showToast({
    title: res.data.msg,
    icon: 'none',
    duration: 1000,
   })
   }else{
   //修改email
   var _student = wx.getStorageSync('student');
   _student.email = email;
   wx.setStorageSync('student', _student);
   
   wx.showToast({
    title: res.data.msg,
    icon: 'success',
    duration: 2000,
    success: function () {
    setTimeout(function () {
     wx.reLaunch({
     url: '../myinfo/myinfo',
     })
    }, 2000)
    }
   })
   }
  },
  })
 }
 },

這里我們用下邊方法從student里只修改email的值。

//修改email
   var _student = wx.getStorageSync('student');
   _student.email = email;
   wx.setStorageSync('student', _student);

wx.setStorageSync(KEY,DATA)

將 data 存儲在本地緩存中指定的 key 中,會覆蓋掉原來該 key 對應的內(nèi)容,這是一個同步接口。

wx.getStorageSync(KEY)

從本地緩存中同步獲取指定 key 對應的內(nèi)容。

如有問題或補充,歡迎小伙伴們留言哦~期待與你一同學習,共同進步?。。?br />

以上所述是小編給大家介紹的微信小程序如何修改本地緩存key中單個數(shù)據(jù)詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論