简体   繁体   English

如何在 React 中使用带有 Ionic 5 应用程序的cordova s​​qlite 插件?

[英]How to use cordova sqlite plugin with Ionic 5 app in React?

I have followed the documentation here , installed cordova-sqlite-storage, @ionic-native/sqlite, and @ionic-core, and have the following code on app.tsx.我已经按照这里的文档安装了cordova-sqlite-storage、@ionic-native/sqlite和@ionic-core,并且在app.tsx上有以下代码。

import { SQLite, SQLiteObject } from '@ionic-native/sqlite/';

function AppSession(props:any){
...


useEffect(()=>{

  SQLite.create({
    name: 'data.db',
    location: 'default'
  }).then((result) => {
    console.log("DONE");
    console.log(result);
  }).catch((err) => {
    console.log("ERROR");
    console.log(err);
  });
},[])

After that I run the app on the browser with the command ionic serve but I am getting the error Cannot read property 'then' of undefined for SQLite.create(...).之后,我使用ionic serve命令在浏览器上运行该应用程序,但出现错误无法读取SQLite.create(...)的 undefined 属性 'then'

I haven't found much on the documentation or the forums.我在文档或论坛上没有找到太多内容。 What am I doing wrong?我究竟做错了什么? What is the right way to use the plugin?使用插件的正确方法是什么?

The problem is probably that you're running the app in the browser.问题可能是您在浏览器中运行该应用程序。 If you build it for a device, I imagine it would work.如果您为设备构建它,我想它会起作用。 Have a look at this repo to see a working example of a simple app using the Cordova SQLite plugin with Ionic React and Capacitor.查看此存储库,查看使用 Cordova SQLite 插件与 Ionic React 和 Capacitor 的简单应用程序的工作示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 React JS 页面中使用 Cordova 插件 - How to use a Cordova plugin in react JS page 在 Android 模拟器上运行应用程序时,如何在 Ionic React 应用程序中使用社区 HTTP 插件? - How to use community HTTP plugin in a Ionic React app when running the app on Android Emulator? 离子 5 反应电容器 / Cordova cordova-plugin-uid - Ionic 5 React Capacitor / Cordova cordova-plugin-uid 如何在react.js页面中使用Cordova插件 - How to use cordova plugin in react.js page 如何使用 cordova 相机插件与 framework7 反应 - how to use cordova camera plugin with framework7 react 如何在 Ionic React 中将 Ionic 与 Angular 工具一起使用? - How to use Ionic with Angular Tools in Ionic React? cordova / cordova-plugin-keyboard和react js。 如何在React JS中正确安装和调用插件方法 - cordova/ cordova-plugin-keyboard and react js. How right install and call methods of plugin in react js 如何将Ionic与Meteor和React结合使用 - How to use Ionic with Meteor and React 将 Ionic Native / Cordova Plugins 与 Ionic (React) & Capacitor 一起使用的正确方法是什么? - What is the right way to use Ionic Native / Cordova Plugins with Ionic (React) & Capacitor? 我怎么能用Cordova和Meteor&React? - How could I use Cordova with Meteor & React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM