[英]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.