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:
// the first method
import dd from 'gdt-jsapi'
dd.getLocation().then(ret => {
console.log(ret)
}).catch(err => {
console.error(err)
})
// the second method
my.getLocation({
success (ret) {
console.log(ret)
},
fail (err) {
console.error(err)
}
})
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
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
import dd from 'gdt-jsapi';
dd.alert({
message: 'hello world'
}).then(res = >{
console.log(res);
}).
catch(err = >{
console.error(err);
});