在 vueJS 中导入 javascript 类 [英] Import javascript class in vueJS
本文介绍了在 vueJS 中导入 javascript 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Vue 应用程序中使用 javascript 类.
I want to use a javascript class in may Vue application.
我的类看起来像:
class className {
constructor() {
...
}
function1() {
...
}
static funtion2() {
...
}
}
我尝试在我的应用程序中导入此类:
I tried to import this class in my application like:
- 从'./fileName.js'导入className;
- var {className} = require('./fileName.js')
在我想调用类的函数时收到的所有情况 (className.function2()
):函数未定义.
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
}
这篇关于在 vueJS 中导入 javascript 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文