【发布时间】:2019-06-18 11:33:03
【问题描述】:
我正在尝试从我的Vue.js component 中的导入助手class 调用JavaScript function。我在component 中import 我的助手class 并尝试使用mounted() 调用它并将参数传递给助手class。
我从这里尝试了一些解决方案,但没有帮助: Vue.js: Import class with function and call it in child component
这是我到目前为止所尝试的,有什么想法吗?
我有一个助手类myHelper.js:
export default myHelper {
myHelperFunction(param) {
return param;
}
}
我有一个Vue 组件MyComponent.vue:
<template>
<v-text-field :rules="[myRule]"></v-text-field>
</template>
<script>
import myHelper from './myHelper.js';
export default {
name: 'MyComponent',
data() {
return {
myCls: new myHelper(),
myRule: this.callHelperFunction,
};
},
components: {
myHelper,
},
mounted() {
this.myCls.myHelperFunction();
},
methods: {
callHelperFunction(param) {
this.myCls.myHelperFunction(param);
}
},
};
</script>
【问题讨论】:
标签: javascript class vue.js vuetify.js