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

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

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

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

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

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

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

然后我添加郵箱后,后臺(tái)接口寫了方法讓email的值直接存到student中,但是如果初次添加email的話可以實(shí)現(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 存儲(chǔ)在本地緩存中指定的 key 中,會(huì)覆蓋掉原來該 key 對(duì)應(yīng)的內(nèi)容,這是一個(gè)同步接口。

wx.getStorageSync(KEY)

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

如有問題或補(bǔ)充,歡迎小伙伴們留言哦~期待與你一同學(xué)習(xí),共同進(jìn)步?。?!

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

相關(guān)文章

最新評(píng)論