程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了“TypeError:item.getAttachmentsAsync 不是函数”Outlook 插件 office-js 与 Vue大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决“TypeError:item.getAttachmentsAsync 不是函数”Outlook 插件 office-js 与 Vue?

开发过程中遇到“TypeError:item.getAttachmentsAsync 不是函数”Outlook 插件 office-js 与 Vue的问题如何解决?下面主要结合日常开发的经验,给出你关于“TypeError:item.getAttachmentsAsync 不是函数”Outlook 插件 office-js 与 Vue的解决方法建议,希望对你解决“TypeError:item.getAttachmentsAsync 不是函数”Outlook 插件 office-js 与 Vue有所启发或帮助;

我一直在关注此链接中的教程:https://docs.microsoft.com/en-us/javascript/api/outlook/office.messageread?view=outlook-js-preview#getAttachmentContentAsync_attachmentId__options__callBACk_ 以尝试从任务窗格中的 Office 加载项的 Outlook 电子邮件中获取附件。我是从 Read 场景中执行此操作,而不是在需求集 1.8 中应该提供的 Compose 场景中。

我已将清单中的要求集更新为 1.8

    <requirements>
        <Sets>
            <Set name="MailBox" MinVersion="1.8"/>
        </Sets>
    </requirements>

以及更新版本覆盖要求集

    <VersionOverrIDes xmlns="http://scheR_944_11845@as.microsoft.com/office/mailappversionoverrIDes" xsi:type="VersionOverrIDesV1_0">
        <requirements>
            <bt:Sets DefaultMinVersion="1.8">
                <bt:Set name="MailBox"/>
            </bt:Sets>
        </requirements>

在我的 Vue 文件中,这是我的代码:

@H_286_7@mounted()
{
    this.loading = true;
    var item = Office.context.mailBox.item;

    console.log(item);
    var options = {asyncContext: {CurrentItem: item}};
    item.getAttachmentsAsync(options,callBACk);

    function callBACk(result)
    {
        console.log("insIDe callBACk");
        console.log(result.value.length)
        if (result.value.length > 0)
        {
            for (let i = 0; i < result.value.length; i++)
            {
                result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].ID,handleAttachmentsCallBACk);
                console.log("function callBACk");
                console.log(result.value[i].ID);
            }
        }
    }

    function handleAttachmentsCallBACk(result)
    {
        console.log("item attachment handler");
        // Parse String to be a url,an .eml file,a base64-encoded String,or an .icalendar file.
        switch (result.value.format)
        {
            case Office.MailBoxEnums.AttachmentContentFormat.base64:
                // Handle file attachment.
                console.log("got base 64");
                console.log("result ----------" + result.value);
                _this.sendrequest(result.value)
                break;
            case Office.MailBoxEnums.AttachmentContentFormat.Eml:
                // Handle email item attachment.
                break;
            case Office.MailBoxEnums.AttachmentContentFormat.ICalendar:
                // Handle .icalender attachment.
                break;
            case Office.MailBoxEnums.AttachmentContentFormat.Url:
                // Handle cloud attachment.
                break;
            default:
            // Handle attachment formats that are not supported.
        }
    }
}

当我运行它时,出现以下错误:

vue.Js:634 [Vue 警告]:v-on 处理程序中的错误:“TypeError:item.getAttachmentsAsync 不是函数”

vue.Js:1897 TypeError: item.getAttachmentsAsync 不是函数 在 VueComponent.mounted (getAttachments.vue:265) 点击 (getAttachments.vue?ccdf:99) 在 invokeWithErrorHandling (vue.Js:1863) 在 HTMLbuttonElement.invoker (vue.Js:2188) 在 HTMLbuttonElement.original._wrapper (vue.Js:7547)

我已经尝试了所有这些,但都没有解决问题,我什至尝试手动获取附件数据但没有成功。因为它在控制台中显示了附件数据,但由于错误而没有进一步。

outlook-addin Office.AttachmentContent interface not working

How get attachments in outlook plugin?

谢谢,感谢您的任何建议。

解决方法

Office.context.mailbox.item.getAttachmentsAsync 仅在撰写模式下可用。如果您正在阅读场景中工作,您可以使用 Office.messageRead 界面上的 attachments property 来获取项目的附件。

例如:

Office.context.mailbox.item.attachments[0].id

将是项目上第一个附件的附件 ID。

大佬总结

以上是大佬教程为你收集整理的“TypeError:item.getAttachmentsAsync 不是函数”Outlook 插件 office-js 与 Vue全部内容,希望文章能够帮你解决“TypeError:item.getAttachmentsAsync 不是函数”Outlook 插件 office-js 与 Vue所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。