Meteor - 核心 API



如果你希望僅在伺服器或客戶端執行程式碼,可以使用以下程式碼:

meteorApp.js

if (Meteor.isClient) {
   // Code running on client...
}

if (Meteor.isServer) {
   // Code running on server...
}

當應用使用 Cordova 捆綁時,你僅可將程式碼限制執行。

if (Meteor.isCordova) {
   // Code running on Cordova...
}

部分外掛需要等到伺服器和 DOM 已準備就緒。可使用以下程式碼等到所有事物開始。

Meteor.startup(function () {
   // Code running after platform is ready...
});

下列表格列出了其他部分核心 API 方法。

序號 方法與詳細資訊
1

Meteor.wrapAsync(function)

用於包裝非同步程式碼並將其轉換為同步。

2

Meteor.absoluteUrl([path], [options])

用於生成指向應用的絕對 URL。

3

Meteor.settings

用於設定部署配置。

4

Meteor.publish(name, function)

用於向客戶端釋出記錄。

廣告
© . All rights reserved.