gpt4 book ai didi

sqlite - 出现错误 ionic3 项目中的类型 'openDatabase' 上不存在属性 'SQLite'?

转载 作者:行者123 更新时间:2023-12-02 00:00:34 25 4
gpt4 key购买 nike

我的错误:

Runtime Error Uncaught (in promise): TypeError: _this.sqlstorage.openDatabase is not a function TypeError: _this.sqlstorage.openDatabase is not a function at http://localhost:8100/build/main.js:67:30 at t.invoke (http://localhost:8100/build/polyfills.js:3:9283) at Object.onInvoke (http://localhost:8100/build/vendor.js:4508:37) at t.invoke (http://localhost:8100/build/polyfills.js:3:9223) at r.run (http://localhost:8100/build/polyfills.js:3:4452) at http://localhost:8100/build/polyfills.js:3:14076 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4499:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9888) at r.runTask (http://localhost:8100/build/polyfills.js:3:5143)

堆栈

Error: Uncaught (in promise): TypeError: _this.sqlstorage.openDatabase is not a function TypeError: _this.sqlstorage.openDatabase is not a function at http://localhost:8100/build/main.js:67:30 at t.invoke (http://localhost:8100/build/polyfills.js:3:9283) at Object.onInvoke (http://localhost:8100/build/vendor.js:4508:37) at t.invoke (http://localhost:8100/build/polyfills.js:3:9223) at r.run (http://localhost:8100/build/polyfills.js:3:4452) at http://localhost:8100/build/polyfills.js:3:14076 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4499:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9888) at r.runTask (http://localhost:8100/build/polyfills.js:3:5143) at c (http://localhost:8100/build/polyfills.js:3:13535) at http://localhost:8100/build/polyfills.js:3:14107 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4499:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9888) at r.runTask (http://localhost:8100/build/polyfills.js:3:5143) at o (http://localhost:8100/build/polyfills.js:3:2203) at HTMLDocument.invoke (http://localhost:8100/build/polyfills.js:3:10985)

我的 Home.ts 文件:

import { Component } from '@angular/core';
import { NavController,Platform } from 'ionic-angular';
import {SQLite} from "@ionic-native/sqlite";

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
sqlstorage: SQLite;
items: Array<Object>;

constructor(public navCtrl: NavController, private platform: Platform) {
this.platform.ready().then(() => {
for (var i = 100000 - 1; i >= 0; i--) {
console.log("test");
}
this.sqlstorage = new SQLite();
this.sqlstorage.openDatabase({name: "items.db", location: "default"}).then(() => {
this.createTables();
this.findAll();
}, (err) => {
console.log("!!! ", err);
});
});

}

public createTables(){
this.sqlstorage.executeSql(`create table if not exists items(
reference CHAR(10) PRIMARY KEY,
name CHAR(30),
qMin FLOAT,
qReal FLOAT
))`, {});
}}

Ionic 版本详细信息

ionic 框架:3.6.0

ionic 应用程序脚本:2.1.3

角度核心:4.1.3

Angular 编译器 CLI:4.1.3

节点:8.2.1

操作系统平台:Linux 4.4

导航器平台:Linux x86_64

用户代理:Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,如 Gecko)Chrome/60.0.3112.78 Safari/537.36

我尝试过:

 npm install --save @ionic-native/sqlite

但没有帮助。

最佳答案

您应该将SQLite注入(inject)到您的构造函数中。而且SQLite似乎没有一个名为openDatabase()的函数。 documentation表示使用函数create(config:SQLiteDatabaseConfig)来创建或打开数据库。

...

private db: SQLiteObject;

constructor(private sqlite: SQLite, private platform: Platform) {
platform.ready().then(() => {
sqlite.create({
name: "items.db",
location: "default"
})
.then(db => {
this.db = db;
this.createTables();
}
});
}

createTables(){
this.db.executeSql(...);
}

...

关于sqlite - 出现错误 ionic3 项目中的类型 'openDatabase' 上不存在属性 'SQLite'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45659278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com