All Products
Search
Document Center

About Mini Program APIs

Last Updated: Feb 04, 2021

The mPaaS framework provides developers with more JSAPI and OpenAPI capabilities, and also provide users with a variety of convenient services through Mini Program.

Notes

APIs starting with my.on are used to listen to system events and receive a callback function as a parameter. When a system event is triggered, the callback function is called, and the callback function can be passed to the corresponding APIs starting with my.off to remove the listner. If you call the APIs starting with my.off directly, all the listners are removed. For example:

 
  1. Page({
  2. onLoad() {
  3. this.callback = this.callback.bind(this);
  4. my.onBLECharacteristicValueChange(this.callback);
  5. },
  6. onUnload() {
  7. // Remove listener when the page is unloaded
  8. my.offBLECharacteristicValueChange(this.callback);
  9. },
  10. callback(res) {
  11. console.log(res);
  12. },
  13. });

All other APIs receive an object as the parameter. You can specify success (call success), fail (call failure), or complete (call success or failure) to receive the interface call result. The result of callback is typically an object unless otherwise specified, and error/errorMessage indicates that the call is failed. The return value after the call is a promise object. For example:

 
  1. my.httpRequest({
  2. url: '/x.htm',
  3. success:(res1) => {
  4. },
  5. }).then((res2) => {
  6. // res1 === res2
  7. },(res2) => {
  8. console.log(res.error, res.errorMessage);
  9. })