# Initialization
Before cloud capabilities can be used in the Mini Program, wx.cloud.init
must be called to complete the initialization of cloud capabilities. (Note that the cloud service must be activated for the Mini Program by clicking Console on the upper left corner of toolbar.) Therefore, to use the cloud capabilities, we generally call this method when the Mini Program is initialized.
The wx.cloud.init
method is defined as below:
function init(options): void
The wx.cloud.init
method accepts an optional options
parameter, and such a method has no return value. The method can only be called once, and only the first call takes effect when multiple calls are made.
The options
parameter defines the default settings for Cloud Base, which are used as the default settings for all other cloud APIs called later on. The optional settings provided by options
are as follows:
Field | Data Type | Required | Default | Description |
---|---|---|---|---|
env | string | object | No | default | The default environment settings. The environment ID in the form of an incoming string can be used to specify the default environment for all services, while the incoming object can be used to specify the default environment for each specific service. Refer to the detailed definition below. |
traceUser | boolean | No | false | Indicates whether to record user access in the user management and display it in the console |
When the incoming env
parameter is an object, it can be used to specify the default environment for each service. The optional fields are as below:
Field | Data Type | Required | Default | Description |
---|---|---|---|---|
database | string | No | default | The default environment settings of database API |
storage | string | No | default | The default environment settings of storage API |
functions | string | No | default | The default environment settings of cloud function API |
Sample code:
wx.cloud.init({
env: 'test-x1dzi'
})
# API Style
The API style of Cloud Base is consistent with that of the framework components, but the callback style and the Promise style are also supported. Among the Object parameters passed in API, if the success
, fail
and complete
fields are passed in, then the callback style is used, and the call of API method does not return Promise
. If the success
, fail
, and complete
fields passed in the Object parameter of API do not exist, then the call of API method returns a Promise
in the Promise style. The result of Promise
resolve is the same as the parameter passed in the success
callback, and the result of reject is the same as the parameter passed in fail
.