【发布时间】:2021-03-30 09:02:21
【问题描述】:
我已经创建了一个类似这样的模块 greatings.js:
function greatings() {
this.hello = function() {
return 'hello!';
}
this.goodbye = function() {
return 'goodbye!';
}
}
module.exports = greatings;
然后我将它导入到VUE.JS中的main.js中,就像:
import greatings from './assets/js/greatings';
Vue.use(greatings);
现在我想在我的组件中使用它,但如果我这样做会出错:
mounted() {
this.greatings.hello();
}
错误:挂载钩子错误:“TypeError:无法读取未定义的属性'hello'”
如何解决它并能够使用我的赞美? 感谢您的帮助!
【问题讨论】:
标签: javascript vue.js module vue-component