I met the search record on the search page today , So how can discipline still exist in the case of refreshing the page
These two introduce a synchronous writing method of wechat applet request data
storage :
wx.setStorageSync(‘list’, ll)
grammar
wx.setStorageSync(‘ The name of the store ’, Stored values )
read :
wx.getStorageSync(‘list’)
grammar
wx.getStorageSync(‘ The name of the store ’)
If stored locally , If you want to refresh the page, we can get the data directly. You can write it like this
* Life cycle function -- Monitor page loading */ onLoad: function (options) { var
list=wx.getStorageSync('list') console.log(list) if(list) { this.setData({
lishi:list }) } wx.request({ url: ' *******************************************
', header: { 'content-type': 'application/json' // Default value }, success:((res)=>{
//console.log(res) this.setData({ list:res.data.list }) }) }) },
In the life cycle of page loading
Judge whether there is local data
If there is one, direct it setData Let him load it in advance data In the data
It can be rendered in advance
Technology