我正在嘗試將第三方API集成到我的meteor.js應用程序中。 所以這個想法是,當在/blog
路線上時,應用程序應該調用外部類的方法。來自導入類的方法undefined
router.js
:
import blog from '../imports/scripts/blog';
FlowRouter('/blog', {
name: 'blog',
action: function(params) {
blog.init(); // here I get the error "init is not a function" (it's undefined)
}
});
blog.js
:
export default class Blog {
constructor(){
...
}
init() {
console.log('init blog api');
...
}
}
爲了使ES2015我使用的是最新的流星(1.4.2.3)和以下NPM包:
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-es2015": "^6.18.0",
"babel-runtime": "^6.18.0",
"meteor-node-stubs": "^0.2.4",
"webpack": "^1.13.3"
我是否在我的設置中丟失了任何我不能撥打blog.init()
?
;'然後你將會有init - 'blog.init()' –
你正在導出一個類,而不是它的一個實例。你應該從'../imports/scripts/blog';'進入Blog,然後是'const blog = new Blog();'。 –