3

当我们第一次安装应用程序时,我已经看到大多数移动应用程序都有一个介绍滑块。我在谷歌上搜索过,但它们都是带有 Angular 的旧版 Ionic。

我对将组件放在哪里以及我应该如何管理状态感到非常困惑。

我在我的应用程序中使用电容器,我认为电容器具有存储功能。

我也想知道做这件事的正确流程是什么。

提前致谢。

4

1 回答 1

1

要记住或跟踪是否在您必须将某种信息存储到设备之前显示滑块。您可以使用localStorage电容器存储插件。我会推荐使用该插件,因为 localStorage 数据可能会在一段时间后被操作系统或用户删除。

这是使用插件实现此目的的过程。

安装和同步插件

如果您使用的是 Capacitor 版本 2 或更低版本,则不必安装它。

npm install @capacitor/storage
npx cap sync

像这样使用它

import { Storage } from '@capacitor/storage';

const { value } = Storage.get({
  key: 'introShowed',
});

if (!value) {
  // logic to show the intro goes here

  // set the value to true so next time this code block will not be executed
  Storage.set({
    key: 'introShowed',
    value: true,
  });
}
于 2022-02-19T17:48:45.340 回答