Ionic 未捕获的类型错误:无法设置vue中未定义的属性“$offlineStorage”?

ar7v8xwq  于 2022-12-08  发布在  Ionic
关注(0)|答案(1)|浏览(118)

I am using this plugin https://github.com/filrak/vue-offline in my vue ionic app when i install this plugin I got this error

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

I checked vue-offline.js file and got to know that this was because of these lines

if (pluginOptions.storage) Vue.prototype.$offlineStorage = VueOfflineStorage;
    if (pluginOptions.mixin) Vue.mixin(VueOfflineMixin);

Whole function was like this

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);
  }
};

I am using in my main.js file

const app = createApp(AppMain)
    .use(IonicVue)
    .use(router)
    .use(RouterPrefetch)
    .use(VueOffline)
    .use(store);

What i am missing in this process?

gev0vcfq

gev0vcfq1#

从v2.0.8开始,vue-offline仅支持Vue 2,但您的Ionic应用需要Vue 3。
有一个开放的GitHub问题(vue-offline#24)需要Vue 3支持。你可以取消这个问题,或者创建你自己的拉取请求来升级插件(参见Vue 3 Migration Guide)。

相关问题