我正在尝试从本地文件(file://)使用IE11使PouchDB的Getting Started Guide正常工作。有可能吗?
通过将以下脚本添加到index.html文件的标题中,可以在本地http服务器上很好地工作:
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fetch.umd.min.js"></script>
[我认为我的问题是在使用file://协议提供服务时,IE都限制了indexedDB和localStorage,但是我可以使用此post中的以下代码来使localStorage自行工作:
!localStorage && (l = location, p = l.pathname.replace(/(^..)(:)/, "$1$$"), (l.href = l.protocol + "//127.0.0.1" + p));
所以我认为这将使其正常工作,但是即使在我添加pouchdb localstorage adapter时,也会出现此错误:“ AssertionError:.status必需,旧的abstract-leveldown”。
即使这样做确实可行,该解决方案也不理想,因为我需要将file://127.0.0.1添加到受信任的站点列表中。
据我所知,任何帮助将不胜感激!
由于Zhi Lv - MSFT评论,我能够使IE11中的演示正常工作,但是它要求用户将'file://127.0.0.1'添加到IE中的受信任站点列表中。
完成“入门”指南后,您需要进行以下更改。
更新index.html文件中的head元素:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>VanillaJS • TodoMVC</title>
<link rel="stylesheet" href="style/base.css">
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fetch.umd.min.js"></script>
<script src="pouchdb/object-assign.js"></script>
<script src="pouchdb/pouchdb-7.2.1.js"></script>
<script src="pouchdb/pouchdb.localstorage.js"></script>
<script src="pouchdb/pouchdb.memory.js"></script>
<!--[if IE]>
<script src="style/ie.js"></script>
<![endif]-->
</head>
您将需要下载所有缺少的7.2.1 pouch-db files,并将其放入pouchdb目录中。可以在here中找到object-assign.js。
修改app.js,用以下两行替换db变量:
!localStorage && (l = location, p = l.pathname.replace(/(^..)(:)/, "$1$$"), (l.href = l.protocol + "//127.0.0.1" + p));
var db = new PouchDB('todos', {adapter: 'localstorage'});
转到pouchdb.localstorage.js的第8796行,如下编辑它以设置db.status:
function LevelUP (db, options, callback) {
db.status = 'unknown';
if (!(this instanceof LevelUP)) {
return new LevelUP(db, options, callback)
}
有点烂,但为我工作。有任何改善,请告诉我。