Meteor 1.3-延迟加载或评估文件
我对Meteor 1.3中的ES2015Meteor 1.3-延迟加载或评估文件,meteor,meteor-react,Meteor,Meteor React,我对Meteor 1.3中的ES2015模块感到非常兴奋。我们已经用Meteor 1.2编写了一个中等复杂度的应用程序。由于我们有大量的模板和文件,在客户端下载内容需要一些时间。因此,我对使用import的延迟加载特性感兴趣。他们说Blaze模板仍然是全局的,无法导入(或延迟加载),我已经尝试过了 使用meteor add react template helper添加了react template helper 创建imports文件夹并添加导出“testComponent”的testCom
模块感到非常兴奋。我们已经用Meteor 1.2编写了一个中等复杂度的应用程序。由于我们有大量的模板和文件,在客户端下载内容需要一些时间。因此,我对使用import
的延迟加载特性感兴趣。他们说Blaze模板仍然是全局的,无法导入(或延迟加载),我已经尝试过了
- 使用meteor add react template helper添加了
react template helper
- 创建
imports
文件夹并添加导出“testComponent”的testComponent.jsx
文件
//testComponent.jsx
import React from 'react';
export default class TestComponent extends React.Component {
render() {
return (
<div>
<h1>TestComponent</h1>
<div>This is from Test Component</div>
</div>
);
}
}
- 在模板的js文件中,该文件也位于导入文件夹之外
// homeReact template js
import { Template } from 'meteor/templating';
import TestComponent from '/imports/testComponent.jsx`;
Template.homeReact.helpers({
TestComponent() {
return TestComponent;
}
});
这是可行的,但是imports/testComponent.jsx
是在客户端下载的(使用chrome开发工具-sources选项卡进行检查),即使当前路由不需要homeReact
模板
然后我使用了require
而不是像这样的import
// homeReact template js
import { Template } from 'meteor/templating';
Template.homeReact.onCreated(function () {
this.TestComponent = require('/imports/testComponent.jsx').TestComponent;
});
Template.homeReact.helpers({
TestComponent() {
return Template.instance().TestComponent;
}
});
这段代码还下载了imports/testComponent.jsx
文件,但除此之外,我还得到了一个错误
在模板“homeReact”中,调用{{>React…}
缺少组件
参数
所以,我的问题是,是否可以只在需要时延迟加载(下载)文件
// homeReact template js
import { Template } from 'meteor/templating';
Template.homeReact.onCreated(function () {
this.TestComponent = require('/imports/testComponent.jsx').TestComponent;
});
Template.homeReact.helpers({
TestComponent() {
return Template.instance().TestComponent;
}
});