sqlite - window.sqlitePlugin 未定义 - 但已安装 sqlite
问题描述
我试图通过. cordova-sqlite-storage
我使用框架7。
看起来插件已安装,因为当我再次输入 install 命令时,我看到了
C:\Users\User\Desktop\pj>cordova plugin add cordova-sqlite-storage
Plugin "cordova-sqlite-storage" already installed on android.
Plugin "cordova-sqlite-storage" already installed on browser.
Adding cordova-sqlite-storage to package.json
这是我使用 sqlite 的代码:routes.js
routes = [
{
path: '/',
url: './index.html',
},
{
path: '/drive/',
url: './pages/drive.html',
on: {
pageInit: function (e, page) {
//db start
window.sqlitePlugin.echoTest(function() {
console.log('ECHO test OK');
alert('ECHO test OK');
});
window.sqlitePlugin.selfTest(function() {
console.log('SELF test OK');
alert('SELF test OK');
});
[...]
在控制台中我看到
TypeError: window.sqlitePlugin is undefined
解决方案
将此添加到您的 index.html,但在任何脚本之前:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="plugins/cordova-sqlite-storage/www/SQLitePlugin.js"></script>
<!-- your other scripts here -->
推荐阅读
- react-native - 如何在不升级到 0.59.x 的情况下在 React Native 中为 Android 构建 64 位版本?
- c# - 在 C# 中反序列化对象的 Json 对象
- react-native - React Native Gifted Chat中如何确定消息渲染顺序?
- java - 不需要正则表达式
- c# - 无法构建我的第一个 hello world Xamarin 项目
- java - Spring Data JPA - 创建自定义查询方法生成器
- swift - 从 Swift 字符串中提取文本
- html - 具有可悬停效果的背景图像图案
- ios - Xcode 11 升级 | 找不到 iPhone X 模拟器 | XRPackageModel 9.0.omo
- r - 如何在 R 中向上滚动和向下滚动