i am encountering an issue with a js file that contains classes with functions.
i have a vue component and i want to create an instance of that class within it.
(when directly copying the file into my <script>
tag, everything works smoothly)
myfile.js
class myclass{
constructor(x){
this.x=x
}
}
within the script tag of the vue component, i am attempting to utilize
<script>
..
mounted(){
let myinstance = new myclass("hi")
console.log(myinstance.x)
}
..
</script>
-- at this point, i will mention what I've attempted (without success) so far, feel free to skip if you prefer a solution --
<script>
import myclass from "myfile.js"
this approach failed indicating that the js file needs to be installed first.
i made an attempt to install it, but encountered errors requesting a package.json file.
i created a package.json in the same directory as myfile.js
{
"name" : "myfile",
"version" : "0.0.1",
"main" : "myfile.js",
"scripts" : {
},
"dependencies": {
}
}
however, i received an error stating Could not install from "....\src\baujs\myfile.js" as it does not contain a package.json file.
i have tried various methods without success, seems like i may be looking in the wrong direction. any guidance would be greatly appreciated. thank you in advance