首页 > 解决方案 > 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

标签: sqlitecordovacordova-plugins

解决方案


将此添加到您的 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 -->

推荐阅读