Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to save and retrieve setting information by WeChat Mini Programs

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will share with you the relevant knowledge points about how WeChat Mini Programs saves and takes out the setting information. the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

After setting the monitoring point, Mini Program will get the latest position, judge the arrival of each monitoring point, leave the situation and play the tone. In many cases, users will want this information to be saved for future use.

That's the topic of the day: save the settings in Mini Program.

API

The location alarm uses the following data cache interface in WeChat Mini Programs API to save the configuration information. This section is from the WeChat Mini Programs development document.

Wx.setStorageSync (KEY,DATA)

Storing the data in the key specified in the local cache will overwrite the corresponding content of the original key, which is a synchronization interface.

Parameter description:

The parameter type is required indicating that keyString is the specified keydataObject/String in the local cache and the content wx.getStorageSync (KEY) to be stored

Gets the content corresponding to the specified key synchronously from the local cache.

Parameter description:

Parameter type is required indicating that keyString is the specified key in the local cache

Code implementation

Setting information

The object to save the operation is an Alarm array, and each Alarm object is structured as follows:

The top half is the data member, and the bottom half is the prototype. What needs to be saved is the data member part. Pay a little attention to the prototype information, which lists the methods of the Alarm class, indicating that the data is an Alarm object.

Save data

Just one line of code.

Wx.setStorageSync ('alarms', this.globalData.alarms)

It's just such a simple operation that all data can be saved. Strictly speaking, the part that represents the state does not need to be saved, but there is no distinction here for simplicity.

Take out the data

If it is a general case, it is only one line.

This.globalData.alarms = wx.getStorageSync ('alarms') | | []

This is the data from which it was taken. It goes like this:

The part of the object property data is the same as when it was saved; the prototype section below is different. The reason should be that API does not recognize the Alam class, so it is saved and fetched only as a generic object.

To solve this problem, the location alarm performs the following processing when fetching data:

Var that = this

Var alarm_array = wx.getStorageSync ('alarms') | | []

Alarm_array.forEach (function (alarm_data) {

That.globalData.alarms.push (new Alarm (alarm_data))

})

First, it is taken out as a general data object, and then an Alarm object is created from the data object.

These are all the contents of the article "how to save and retrieve WeChat Mini Programs's setting information". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report