The interface calling of the DingTalk mini program supports two calling methods. The first method is toimport JSAPI. The second method to callby “my”. Each method enjoys its own advantages with the main differencesas follows:

  • The first method: It is called by the returned “Promise”, which more conforms to coding habits.
  • The second method:It does not need to import JSAPI separately. The basic API can be used directly, and the calling methodis by“callback”.

Note: Only basic API is supported if it is called by “my”. To open the related API, it is still necessary to call by importing JSAPI.

The following is an example of the first and the second method:

  1. // the first method
  2. import dd from 'gdt-jsapi'
  3. dd.getLocation().then(ret => {
  4. console.log(ret)
  5. }).catch(err => {
  6. console.error(err)
  7. })
  8. // the second method
  9. my.getLocation({
  10. success (ret) {
  11. console.log(ret)
  12. },
  13. fail (err) {
  14. console.error(err)
  15. }
  16. })

Both methods can be used, mainly according to your own development needs.

The first method is recommended in DingTalk documents. If you want to use the second method for calling, just change “Promise” into “callback”.

Installation

Perform under the project root directory

  1. npm install gdt-jsapi

It is recommended to use “npm” package to import according to demand

Instruction for use

The mini program can be imported in the following way

  1. import dd from 'gdt-jsapi';
  2. dd.alert({
  3. message: 'hello world'
  4. }).then(res = >{
  5. console.log(res);
  6. }).
  7. catch(err = >{
  8. console.error(err);
  9. });