微信小程序中怎么存setStorage?

在js中存入setStorage,key是你的键,data是你的值

wx.setStorage({

key: 'mm',

data: 1,

})

// 获取getStorageSync的方式

console.log(wx.getStorageSync('mm')) #获取的方式

接下来是或数据中的存取 ,其实是一样的啦,直接上代码

js文件中代码。

onLoad: function (options) {

var thit = this

wx.request({ //请求地址

url: 'http://127.0.0.1:8000/api/index/',

method: 'get',

// data:{},//没有数据可以不写

header: { //请求头

'content-type': 'application/json'

// "Content-Type": "application/x-www-form-urlencoded"

},

//如果在sucess直接写this就变成了wx.request()的this了

success: function (res) {

// res.data相当于ajax里面的data,为后台返回的数据

//打印后台返回的数据

console.log(res.data.message)

//直接把后台返回的数据 赋值给names 就可以直接调用names了

thit.setData({

names: res.data.message,

names1: res.data.message1, //返回的第二条数据

names2: res.data.message2 // 第三条数据

})

// 存入setStorage

wx.setStorage({

key: 'kkk',

data: res.data.message2, //存第三条数据

})

//查看方式 定义一个变量

var eee = wx.getStorageSync('kkk')

console.log(eee)

}

})

},