本文介绍了本机脚本中是否有本地存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在应用程序中的页面之间共享数据.任何人都可以在本机脚本中讲述本地存储吗?

How to share the data across the pages which resides in application.Can anyone tell about localstorage in nativescript?

推荐答案

您可以将其与global.foo一起使用,它将对整个应用程序可用,也可以使用应用程序设置模块

You can use either with global.foo, it will available for whole app or you can use application-settings module

var applicationSettings = require("application-settings");
//set somewhere like this
applicationSettings.set<Number|String|Boolean>("sharedVar",1);

//get sharedVar somewhere
applicationSettings.get<Number|String|Boolean>("sharedVar");//if empty it will be null

//or if u want default value if sharedVar wasn't defined
//and if sharedVar was defined then u will get content of sharedVar
applicationSettings.get<Number|String|Boolean>("sharedVar","Default Value");

DOCS :

https://docs.nativescript.org/api-reference/modules/_application_settings_.html

编辑:输入错误不是全局变量,而是全局:D

EDIT: had typo not globals but global :D

EDIT2 :从applicationSettings更改函数名称并链接到文档

EDIT2: change names of function from applicationSettings and link for docs

这篇关于本机脚本中是否有本地存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 22:21