javascript - 未捕获的类型错误:无法在 vue 中设置未定义的属性“$offlineStorage”?
问题描述
当我安装这个插件时,我在我的 vue ionic 应用程序中使用这个插件https://github.com/filrak/vue-offline我收到了这个错误
vue-offline.js?bf4e:193 Uncaught TypeError: Cannot set property '$offlineStorage' of undefined
at Object.install (vue-offline.js?bf4e:193)
at Object.use (runtime-core.esm-bundler.js?5c40:2945)
at eval (main.js?56d7:139)
at Module../src/main.js (app.js:1308)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at Object.1 (app.js:1644)
at __webpack_require__ (app.js:854)
at checkDeferredModules (app.js:46)
at app.js:994
我检查了 vue-offline.js
文件并知道这是因为这些行
if (pluginOptions.storage) Vue.prototype.$offlineStorage = VueOfflineStorage;
if (pluginOptions.mixin) Vue.mixin(VueOfflineMixin);
整个功能是这样的
var VueOfflinePlugin = {
install: function install(Vue) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
mixin: true,
storage: true
};
var pluginOptions = {
mixin: options.mixin,
storage: options.storage
};
if (pluginOptions.storage) Vue.prototype.$offlineStorage = VueOfflineStorage;
if (pluginOptions.mixin) Vue.mixin(VueOfflineMixin);
}
};
我在我的 main.js 文件中使用
const app = createApp(AppMain)
.use(IonicVue)
.use(router)
.use(RouterPrefetch)
.use(VueOffline)
.use(store);
我在这个过程中缺少什么?
解决方案
从 v2.0.8 开始,vue-offline
仅支持 Vue 2,但您的 Ionic 应用程序需要 Vue 3。
有一个开放的 GitHub 问题 ( vue-offline#24
) 请求 Vue 3 支持。您可以解决这个问题,或者创建您自己的升级插件的拉取请求(请参阅Vue 3 迁移指南)。
推荐阅读
- artificial-intelligence - 求解具有连续动作空间的多臂老虎机问题
- xml - XSL - 从网络上的目录生成文件列表
- flutter - Flutter Reorderable List 回到原来的状态
- .net-core - ServiceBus 触发器未触发
- angular - Apex图表填充颜色在Angular中面临问题
- php - 在 Magento 1.9 中创建一个给出 404 错误的模块
- neo4j - 使用neo4j在neo4j中查找当前用户不相关的节点
- java - 当 REST API 返回较大的响应时,为什么 Chrome 会关闭连接?
- magento2 - 在 Magento 2 中显示所有产品
- angular - Angular 发布请求在邮递员中有效,但在 Angular 中无效