龙哥不管事 2022-08-15 09:59 采纳率: 0%
浏览 1109
已结题

uni-app中使用onlyoffice报DocsApi is not defined

uni-app中使用onlyoffice报DocsApi is not defined
<template>
    <div id="monitorOffice"></div>
</template>
<script>
    import { handleDocType } from '@/common/util.js'
    export default {
        data() {
            return { doctype: '', DocEditor: null,script:null }
        },
        onLoad(e) {
            let head = document.getElementsByTagName('head')[0]
            let script = document.createElement('script')
            script.type = 'text/javascript'
            script.src = 'http://ip:port/web-apps/apps/api/documents/api.js'
            head.appendChild(script)

            if (this.DocEditor !== null) {
                this.DocEditor.destroyEditor()
            }
            let filePath = JSON.parse(e.item).filePath
            let fileType = filePath.substring(filePath.lastIndexOf('.') + 1)
            let config = {
                'editorConfig': {
                    'lang': 'zh',
                    'mode': 'view',
                    'region': 'zh_CN',
                    'customization': {
                        'chat': false,
                        'comments': false,
                        'zoom': 150,
                    },
                },
                'document': {
                    'fileType': handleDocType(fileType),
                    'key': filePath,
                    'title': '体检报告',
                    'url': filePath
                },
                'documentType': handleDocType(fileType),
                'events': {
                    onError: function(event) {
                        console.log('改文件不支持在线查看')
                    }
                },
                width: '100%',
                height: '100%',
            }
            let docsEditor = new DocsApi.DocEditor('monitorOffice', config)
        },
        methods: {}

    }
</script>

代码编译的时候报错:

[system]ReferenceError: DocsApi is not defined
    at VueComponent.onLoad (webpack-internal:///ppe8:48:22)
    at invokeWithErrorHandling (http://localhost:8080/static/js/chunk-vendors.js:3275:26)
    at VueComponent.push.4UNb.Vue.__call_hook (http://localhost:8080/static/js/chunk-vendors.js:10023:17)
    at r (http://localhost:8080/static/js/chunk-vendors.js:13559:369161)
    at a (http://localhost:8080/static/js/chunk-vendors.js:13559:369739)
    at VueComponent.created (http://localhost:8080/static/js/chunk-vendors.js:13559:9092)
    at invokeWithErrorHandling (http://localhost:8080/static/js/chunk-vendors.js:3275:57)
    at callHook (http://localhost:8080/static/js/chunk-vendors.js:5681:7)
    at VueComponent.Vue._init (http://localhost:8080/static/js/chunk-vendors.js:6466:23)
    at new VueComponent (http://localhost:8080/static/js/chunk-vendors.js:6612:12)

遇到这种情况改怎么处理呢

  • 写回答

4条回答 默认 最新

  • 崽崽的谷雨 2022-08-15 10:04
    关注

    引入对应的 js文件了吗

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月12日
  • 修改了问题 8月15日
  • 创建了问题 8月15日

悬赏问题

  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错