My third party script has code of the following format
( function initialMethod(scope, factory) {
// 'scope' here is UNDEFINED when used in Vue
// but it is fine in React and Angular
} (this, function function1(param1) {
.....
}
)
....
function MyMethod() {....}
....
)
I import a method from this third party library using the following
import {MyMethod} from 'ThirdPartyScript'
When I do this in React or Angular it works perfectly fine.
When using Vue it fails. The "scope"/"this" is undefined. Sample Vue code
<template>
<div id="app">
<p>Hello</p>
</div>
</template>
<script>
import {MyMethod} from 'ThirdPartyScript';
export default {
name: 'app',
created: function () {
this.initApp();
},
methods: {
initApp: function () {
//const myResult = MyMethod();
}
}
</script>
This error appears as soon as i include the "import" statement for the 3rd party library (as apposed to when I call a method from it) as when I call the import statement I believe it executes the "initialMethod" as has () after it telling it to execute.
Why is this different in Vue? Do i have to set up something different when using Vue?
Environment info
I used Vue CLI to create my project, the package.json has the following versions mentioned
dependencies": {
"core-js": "^2.6.5",
"vue": "^2.6.10",
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.11.0",
"@vue/cli-plugin-eslint": "^3.11.0",
"@vue/cli-service": "^3.11.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"vue-template-compiler": "^2.6.10"
},
Update
if i change the "this" in the 3rd party library to "window" I get a little further, but now on the following call
const myResult = MyMethod();
I get the error "Object(...) is not a function" for "MyMethod"