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:
import className from './fileName.js';
var {className} = require('./fileName.js')
In all cases I receive when I want to call a function of the class (className.function2()): the function is undefined.
解决方案
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
}