2

While developing a Phonegap app I use Vuex to manage app's state. So, I have at App.vue:

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

Later I want to create an annual subscription, for which I use the cordova-plugin-purchase plugin (https://github.com/j3k0/cordova-plugin-purchase), which exports a global object called 'store'.

So when I try to use the 'register' method of this plugin I get an error saying that there is no 'register' method for Vuex:

store.register()

"TypeError: _vuex_store__WEBPACK_IMPORTED_MODULE_0__["default"].register is not a function."

How can I avoid this conflict provided that this is the most updated and viable plugin to create IAP for Cordova projects?

Here is my code:

At app.js:

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

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

At App.vue:

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

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

At 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); ...

Later in component to set the IAP:

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

I should add that I'm using Framework7 + Vue + Webpack

hoozer
  • 23
  • 1
  • 5
  • You can call Vuex `store` by any name you want when you import it. `import vuexstore from './vuex/store'` – Dan Apr 13 '20 at 10:35
  • @Dan Doing what you propose arises a new different error: "undefined is not an object (evaluating '_this.$vuexstore.dispatch')" when using dispatch method. – hoozer Apr 13 '20 at 11:23

1 Answers1

0

Try this:

import vuexstore from './vuex/store';

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

Use it in components as this.$store as usual

Do you have a reason to import the Vuex store in the IAP component? There shouldn't be, since vuex would be accessible through this.$store.

Try not importing the Vuex store in that component and simply logging the other global object however you would use it. Right now it doesn't appear that you import or use the non-Vuex store anywhere.

Dan
  • 59,490
  • 13
  • 101
  • 110
  • Unluckily this brings the first error again, the one about 'register' is not a function... – hoozer Apr 13 '20 at 11:48
  • Hmm, that should be impossible. We need to see the details of how you import and use both stores and register all in one file – Dan Apr 13 '20 at 11:54
  • 1
    I think my error was importing store again in component. I don't know why I did that but removing the import it seems to work fine. Thanks for your time. – hoozer Apr 13 '20 at 12:28