从Vue.js组件数据中导入的帮助器类调用函数

时间:2019-06-18 11:33:03

标签: javascript class vue.js vuetify.js

我正在尝试从我的sum() JavaScript中的导入助手function调用class Vue.js。我在componentimport我的助手class,并尝试使用component来调用它,并将参数传递给助手mounted()

我从这里尝试了一些解决方案,但没有帮助: Vue.js: Import class with function and call it in child component

https://forum.vuejs.org/t/how-to-use-helper-functions-for-imported-modules-in-vuejs-vue-template/6266

这是我到目前为止尝试过的,有什么想法吗?

我有一个辅助课程class

myHelper.js

我有一个export default myHelper { myHelperFunction(param) { return param; } } 组件Vue

MyComponent.vue

1 个答案:

答案 0 :(得分:2)

您并不是真的要导出类。这是一个普通的对象。要导出类而不是对象,请执行以下操作:

// Notice the use of class keyword
export default class MyHelper {
    myHelperFunction(param) {
        return param;
    }
}

此外,您不需要:

components: {
    myHelper,
},

其余代码保持不变。