HarmonyOS NEXT - Stage模型应用 坑点-PersistentStorage的初始化要写在页面的 Entry 上方进行初始化,否则持久化容易失效。

如:需要在应用入口 @Entry 初始化 PersistentStorage

import { Home } from '@ohos/home';
import { SimpleMode } from '@ohos/home';
import { BreakpointConstants, CommonConstants, AppStorageSystemKey} from '@ohos/commons';
import { BusinessError } from '@kit.BasicServicesKit';
import router from '@ohos.router';

/**
 * 坑点-PersistentStorage的初始化要写在页面的 Entry 上方进行初始化,否则持久化容易失效。
 */
 PersistentStorage.persistProp("LOCAL_STORAGE","");

@Entry
@Component
struct Index {}

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐