I want to use a javascript class in may Vue application.
My class looks like:
class className { 
   constructor() { 
       ... 
   }  
   function1() { 
       ... 
   }  
   static funtion2() {
        ... 
   } 
}
I tried to import this class in my application like:
In all cases I receive when I want to call a function of the class (className.function2()): the function is undefined.
A Vue application/web page is built of components that represent encapsulated elements of your interface. Components can be written in HTML, CSS, and JavaScript without dividing them into separate files.
Vue is a JavaScript framework and therefore you can insert vanilla code anywhere in it and it will run perfectly fine.
You need to export the class to be able to import/require it
//1. For import syntax
export default class className {...}
//2. For require syntax
class className {}
module.exports.className = className
//or
module.exports = {
    className: className
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With