钉钉 H5微应用中 遇到的关于调用接口的问题(react框架)

最近开发一个钉钉H5微应用,eslint检查在调用钉钉接口时报错
使用:

componentDidMount() {
    dd.biz.navigation.setTitle({
        title : "消息详情",
        onSuccess : function(result) {
            console.log('success')
        },
        onFail : function(err) {
            console.log('fail')
        }
    });
};

报错如下:
'dd' is not defined no-undef

解决如下:
方法一:

componentDidMount() {
        // eslint-disable-next-line
        dd.biz.navigation.setTitle({
            title : "消息详情",
            onSuccess : function(result) {
                console.log('success')
            },
            onFail : function(err) {
                console.log('fail')
            }
        });
    };

加了一条注释,eslint在会跳过检查,就不会报错了。

方法二:
引入依赖包 dingtalk-jsapi
在需要页面导入依赖后需要的地方进行使用。使用方法如下:

 dd.ready(()=>{
    dd.biz.navigation.setTitle({
      title : "消息详情",
      onSuccess : function(result) {},
      onFail : function(err) {}
    });
})
dd.error(function(err){
    alert('dd error: ')
});
发布了39 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/YYYYYun/article/details/93747138