有时对话框内容不显示

问题描述 投票:0回答:1
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) {}
                      
            }
        }
    }

每次都会显示对话框内容。

angular ms-word office-js
1个回答
0
投票

首先,在

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) {
            
        }
    );
}
© www.soinside.com 2019 - 2024. All rights reserved.