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

WeChat Mini Programs's method of data Storage, Parameter transfer and data caching pair

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "the methods of WeChat Mini Programs's data storage, parameter transfer and data cache pair". In the daily operation, it is believed that many people have doubts about the methods of WeChat Mini Programs's data storage, parameter transfer and data cache pair. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the questions of "WeChat Mini Programs's method of data storage, parameter transfer and data caching". Next, please follow the editor to study!

Go to GIF first:

1.APP.js

I put parameters that are commonly used and will not be changed in the data of APP.js. You can get var app = getApp () in each page.

You can get the parameters stored in data on app.

2. URL carries parameters in wx.navigateTo ({})

Demo has written:

Wx.navigateTo ({url: ".. / newpage/newpage?infofromindex=" + this.data.infofromindex,})

Notes for passing parameters between pages

3.wx.setStorage (OBJECT) data caching

Data caching methods in Wechat development documents:

① stores data

Try {wx.setStorageSync ('infofrominput', this.data.infofrominput)} catch (e) {}

② acquires data

/ / get wx.getStorage ({key: 'infofrominput', success: function (res) {_ this.setData ({infofromstorage: res.data,})}})

Key is the specified key,data in the local cache that needs to be stored.

For more information, please see WeChat Mini Programs Development document: documentation

Paste the code:

1.index.js

/ / index.js / / get the application instance var app = getApp () Page ({data: {info: app.data.info, infofromindex: 'information from index.js', infofrominput:'}, onLoad: function () {}, / / Jump to the new page gotonewpage: function () {wx.navigateTo ({url: ".. / newpage/newpage?infofromindex=" + this.data.infofromindex,}) }, / / get the input value searchInputEvent: function (e) {console.log (e.detail.value) this.setData ({infofrominput: e.detail.value})}, / / Save parameter saveinput: function () {try {wx.setStorageSync ('infofrominput', this.data.infofrominput)} catch (e) {}}))

2.index.wxml

Jump to Storage

3.newpage.js

/ / newpage.js / / get the application instance var app = getApp () Page ({data: {infofromapp: app.data.infofromapp, infofromindex:', infofromstorage:',}, onLoad: function (options) {var _ this = this; var infofromindex = options.infofromindex) This.setData ({infofromindex: infofromindex}) / / get wx.getStorage ({key: 'infofrominput', success: function (res) {_ this.setData ({infofromstorage: res.data,})

4.newpage.wxml

Infofromapp: {{infofromapp}} infofromindex: {{infofromindex}} infofromstorage: {{infofromstorage}}

5.app.js

/ / app.js App ({data: {infofromapp: 'information from APP.js'}, onLaunch: function () {}}) this ends the study of "WeChat Mini Programs's method of data storage, parameter passing and data cache alignment", hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report