Den*_*ieu 6 javascript node.js meteor
我创建了测试Meteor应用程序,我发现可以在客户端上使用dev工具查看整体代码(服务器端).测试应用程序(在浏览器中):
(function(){ if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Welcome to test_app.";
};
Template.helo.events({
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
}).call(this);
Run Code Online (Sandbox Code Playgroud)
这是设计的吗?服务器端代码可以留在服务器上吗?
Aks*_*hat 13
如果要将服务器端代码保留在服务器上,则必须重新构建应用程序.
在应用程序的根目录中创建这些目录:
http://yoursite/(即图像,字体).如果您a.jpg在/public其中放置图像,将在http://yoursite/a.jpg使用此结构后,您不必再使用if(Meteor.isServer) {..}或if(Meteor.isClient) {..}条件,因为它们会在正确的位置运行.
当您将文件放在meteor应用程序的根目录中时,它们将在客户端和服务器上运行,因此这就是文件未更改的原因,if(Meteor.isServer)并且只能在服务器上运行.
它是设计的,在服务器和客户端之间共享代码非常有用,尽管它对客户端和服务器都是可见的
| 归档时间: |
|
| 查看次数: |
1531 次 |
| 最近记录: |