找不到模块“应用程序设置”

Khu*_*shi 3 typescript nativescript angular

尝试包含“应用程序设置模块”时出现错误。

*找不到模块“应用程序设置”<-----错误

错误在我的 storage.driver.ts 中,它位于使用环回 sdk 构建器构建的 nativescript sdk 中

storage.driver.ts

import * as AppSettings from 'application-settings'; <---- Error here
export class StorageDriver {
static set(key: string, value: any) {
AppSettings.setString(key, String(value));
}
static get(key: string): any {
return AppSettings.getString(key);
}
static remove(key: string): any {
if (AppSettings.hasKey(key)) {
  AppSettings.remove(key);
} else {
  console.log('Trying to remove unexisting key: ', key);
}
}
}
Run Code Online (Sandbox Code Playgroud)

我应该怎么做才能解决这个问题?我是 nativescript 的新手。

小智 9

'application-settings'已移至'tns-core-modules',现在已弃用为'application-settings',其他核心 nativescript 模块现在是'@nativescript/core' 的一部分

现在我们使用'@nativescript/core'而不是'tns-core-modules'

@已弃用

import * as AppSettings from 'tns-core-modules/application-settings';
Run Code Online (Sandbox Code Playgroud)

改用这个:

import * as AppSettings from '@nativescript/core/application-settings';
Run Code Online (Sandbox Code Playgroud)


bla*_*hub 0

这就是您导入它的方式

const applicationSettings = require('tns-core-modules/application-settings')

// or if you are using webpack for example
import * as applicationSettings from 'tns-core-modules/application-settings'
Run Code Online (Sandbox Code Playgroud)