Get the App
SLTechnology News&Howtos  ›  Development  › 

The methods of data Storage, Parameter transfer and data caching in WeChat Mini Programs's Development

Shulou Source: shulou.com Published: 2022-05-31 21:00:08 09月15日 Update

The knowledge points of this article "methods of data Storage, Parameter transfer and data caching in WeChat Mini Programs Development" are not quite understood by most people, so the editor summarizes the following contents, which are detailed and clear, and have a certain reference value. I hope you can get something after reading this article. Let's take a look at this article entitled "methods of data storage, parameter transfer and data caching in WeChat Mini Programs development".

Effect 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 () {}}) the above is about the methods of data storage, parameter transfer and data caching in WeChat Mini Programs's development. I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, Please follow the industry information channel.

Tags: Data parameters cache content storage development methods small programs documents information examples articles knowledge articles pages applications previous generation value for the most part Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno vpn Linux Xiaomi Redmi