我想加载localforage与require.js库,但不能得到它的工作。这里是我的require.js配置:localforage与Require.js
main.html中:
<body>
<script type="text/javascript" src="/xyz/js/lib/require-2.1.22.js"> </script>
<script type="text/javascript" src="/xyz/js/main.js?version=1.0.0"></script>
</body>
main.js:
var appVersion = "1.0.0";
requirejs.config({
baseUrl: "../js",
paths: {
jquery: "lib/jquery-1.12.1",
jquery_caret: "lib/jquery.caret-1.5.1",
lodash: "lib/lodash-4.5.1",
localforage: "lib/localforage"
},
shim: {
jquery_caret: ["jquery"]
},
urlArgs: "version=" + appVersion
});
var scriptSources = ["jquery", "jquery_caret", "localforage", "lodash"];
require(scriptSources, function() {
//all scripts loaded
});
但是,当我后来TY使用localforage这样
localforage.setDriver(localforage.INDEXEDDB).then(function() {
console.log("Hi there");
});
它总是未定义的。顺便说一句。与Dexie我遇到同样的问题。 当我从README
define(['localforage'], function(localforage) {
// As a callback:
localforage.setItem('mykey', 'myvalue', console.log);
// With a Promise:
localforage.setItem('mykey', 'myvalue').then(console.log);
});
我从requirejs.org/docs/errors.html#mismatch 收到错误添加以下代码,但它是什么意思?有人可以向我解释吗?我真的不明白。
与此同时,在我看来,我必须将上述定义调用从“define(['localforage'],function(localForage)”更改为“define('localforage',['localforage'],function (localForage)“,现在呼叫不再是匿名了,但是'localforage'仍然没有定义! –
如果其他人感兴趣我已经通过使用这里的解决方案使它工作了,即使我没有使用缩小版本:https://github.com/mozilla/localForage/issues/58 –