async function openDialog(event) {
let url = 'localhost:4200/#/openDialog';
await Office.context.auth.getAccessTokenAsync(gettoken);
function gettoken(res) {
try {
token = res.value;
} catch(err) {
console.log(err);
}
Office.context.ui.displayDialogAsync(
`${url}/${token}`,
{ width: 40, height: 53, displayInIframe: true },
function (result) {}
}
}
}
每次都会显示对话框内容。
首先,在
try
中调用API,然后将响应值存储在res
中,然后尝试下面的代码。
async function openDialog(event) {
let url = 'localhost:4200/#/openDialog';
let token;
try {
const res = await Office.context.auth.getAccessTokenAsync();
token = res.value;
} catch (err) {
console.error('Error getting access token:', err);
return;
}
Office.context.ui.displayDialogAsync(
`${url}/${token}`,
{ width: 40, height: 53, displayInIframe: true },
function (result) {
}
);
}