首页 > 解决方案 > 未捕获的类型错误:无法在 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);

我在这个过程中缺少什么?

标签: javascriptvue.jsionic-frameworkvuejs2vuejs3

解决方案


从 v2.0.8 开始,vue-offline仅支持 Vue 2,但您的 Ionic 应用程序需要 Vue 3。

有一个开放的 GitHub 问题 ( vue-offline#24) 请求 Vue 3 支持。您可以解决这个问题,或者创建您自己的升级插件的拉取请求(请参阅Vue 3 迁移指南)。


推荐阅读