[Vuejs]-How do I pass arguments to an IIFE in vue from vuex store?

0👍

Check if the state variable is globally available in all adjacent .js files. If so you could modify the IIFE to inject a third argument, which would be your state variable.

I think that your object notation of the state variable should be like this.

state = {
  flow: flow.NEW_USER
}

Give the IIFE a third parameter called s (or whatever you prefer).

(function (w, o, s) {
  'use strict'

      ...

      o.oo_feedback = new o.Ocode({
        referrerRewrite: {
          searchPattern: /:\/\/[^/]*/,
          replacePattern: replacePattern
        },
        customVariables: {
          flow: s.flow, // flow.NEW_USER is now here
          clientId: '',
          srcCorrelationId: '',
          visitorId: '',
          sAccount: ''
        }
      })

     ...

})(window, OOo, state)

And inject the state variable here at the bottom.

Now this only works if you have global access to your state variable. And it has to be defined before the IIFE is executed.

Leave a comment