避免 Vuex 与 Phonegap 应用程序中的 IAP 插件之间的冲突

Avoid conflict between Vuex an IAP plugin in Phonegap app

在开发 Phonegap 应用程序时,我使用 Vuex 来管理应用程序的状态。所以,我在 App.vue:

// Import store
import store from './vuex/store'

稍后我想创建一个年度订阅,为此我使用 cordova-plugin-purchase 插件 (https://github.com/j3k0/cordova-plugin-purchase),它导出一个名为 'store' 的全局对象。

所以当我尝试使用这个插件的 'register' 方法时,我得到一个错误,说 Vuex 没有 'register' 方法:

store.register()

"TypeError: _vuex_store__WEBPACK_IMPORTED_MODULE_0__["default"].register 不是函数。"

如果这是为 Cordova 项目创建 IAP 的最新且可行的插件,我该如何避免这种冲突?

这是我的代码:

在app.js:

// Init App
new Vue({
  el: '#app',
  template: '<app/>',

  // Register App Component
  components: {
    app: App
  }
});

在App.vue:

// Import store
    import store from './vuex/store'

    export default {
        store,
        data() {
            return {...

在Login.vue:

if (response.data.result === 'OK') {

                            this.$store.dispatch('setUserID', response.data.user._id);
                            this.$store.dispatch('setUserEmail', response.data.user.email);
                            this.$store.dispatch('setUserName', response.data.user.name); ...

稍后在组件中设置 IAP:

<script>
import store from "../vuex/store";
...
mounted() {
    // Register the product
    store.register([ // being referred here to IAP global store object
      {
        id: ...

我应该补充一点,我使用的是 Framework7 + Vue + Webpack

试试这个:

import vuexstore from './vuex/store';

// Main
new Vue({
  store: vuexstore,
  render: h => h(App)
}).$mount("#app");

像往常一样this.$store在组件中使用它

在IAP组件中导入Vuex store有什么理由吗?不应该有,因为可以通过 this.$store.

访问 vuex

尽量不要在该组件中导入 Vuex 存储并简单地记录其他全局对象,但是您会使用它。现在您似乎没有在任何地方导入或使用非 Vuex 商店。