1、下载钉钉提供的前端JSAPI包
npm install dingtalk-jsapi
2、引入包
import * as dd from "dingtalk-jsapi";
3、封装公用方法
创建文件commonFunc.js
const func ={
// 设置导航栏标题
changeDocumentTitle(title) {
// 钉钉浏览器内部,使用钉钉提供的JSAPI中的接口dd.biz.navigation.setTitle设置导航栏标题
if(window.navigator.userAgent.includes("DingTalk")) {
dd.biz.navigation.setTitle({
title,
onSuccess : (result)=> {
console.log(result);
},
onFail : (err)=> {
console.log(result);
}
})
} else document.title = title;//其他浏览器
}
}
export default func;
4、调用方法时
第一步,导入
import func from "./commonFunc";
第二步使用
func.changeDocumentTitle('这是我的标题啊');