在Vuejs中使用CKeditor5上传图像时遇到问题.

首先,我try 了Simple upload Adapter次,这给了我以下错误:

原因:ckeditor错误:ckeditor重复模块:某些ckeditor 5模块重复.阅读更多:https://ckeditor.com/docs/ckeditor5/latest/framework/guides/support/error-codes.html#error-ckeditor-duplicated-modules

我试着制作一个上传适配器.作为上传适配器,我使用了example并修改了url.上传适配器.js文件如下所示:

    export default class UploadAdapter {
        constructor( loader ) {
            // The file loader instance to use during the upload.
            this.loader = loader;
        }
    
        // Starts the upload process.
        upload() {
            return this.loader.file
                .then( file => new Promise( ( resolve, reject ) => {
                    this._initRequest();
                    this._initListeners( resolve, reject, file );
                    this._sendRequest( file );
                } ) );
        }
    
        // Aborts the upload process.
        abort() {
            if ( this.xhr ) {
                this.xhr.abort();
            }
        }
    
        // Initializes the XMLHttpRequest object using the URL passed to the constructor.
        _initRequest() {
            const xhr = this.xhr = new XMLHttpRequest();
    
            xhr.open( 'POST', '<url here>', true );
            xhr.responseType = 'json';
        }
    
        // Initializes XMLHttpRequest listeners.
        _initListeners( resolve, reject, file ) {
            const xhr = this.xhr;
            const loader = this.loader;
            const genericErrorText = `Couldn't upload file: ${ file.name }.`;
    
            xhr.addEventListener( 'error', () => reject( genericErrorText ) );
            xhr.addEventListener( 'abort', () => reject() );
            xhr.addEventListener( 'load', () => {
                const response = xhr.response;
    
                if ( !response || response.error ) {
                    return reject( response && response.error ? response.error.message : genericErrorText );
                }
   
                resolve( {
                    default: response.url
                } );
            } );
    
            if ( xhr.upload ) {
                xhr.upload.addEventListener( 'progress', evt => {
                    if ( evt.lengthComputable ) {
                        loader.uploadTotal = evt.total;
                        loader.uploaded = evt.loaded;
                    }
                } );
            }
        }
    
        // Prepares the data and sends the request.
        _sendRequest( file ) {
            // Prepare the form data.
            const data = new FormData();
    
            data.append( 'upload', file );
    
            // Send the request.
            this.xhr.send( data );
        }
    }

Vue组件:

    <template>
        <form @submit.prevent="store">
            <ckeditor
                :editor="editor"
                v-model="form.content"
                :error-messages="errors.content"
                :config="editorConfig"
            />
        </form>
    </template>
    
    <script>
        import CKEditor from '@ckeditor/ckeditor5-vue';
        import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
        import UploadAdapter from '../../UploadAdapter';
    
        export default {
            data()
            {
                return {
                    form: {
                        content: null,
                    },
                    editor: ClassicEditor,
                    editorConfig: {
                        toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', '|', 'insertTable', '|', 'imageUpload', 'mediaEmbed', '|', 'undo', 'redo' ],
                        table: {
                            toolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
                        },
                        extraPlugin: [this.uploader],
                        language: 'nl',
                    },
                }
            },
    
            methods: {
                store()
                {
                    // Some code
                },
    
                uploader(editor)
                {
                    editor.plugins.get( 'FileRepository' ).createUploadAdapter = ( loader ) => {
                        return new UploadAdapter( loader );
                    };
                },
            },
    
            components: {
                ckeditor: CKEditor.component
            }
        }
    </script>

但是,每次try 上载文件时,都会返回以下警告:

filerepository无上载适配器:未定义上载适配器.阅读更多:https://ckeditor.com/docs/ckeditor5/latest/framework/guides/support/error-codes.html#error-filerepository-no-upload-adapter

我看过网址,但它只是把我圈起来,因此没有任何进展.我要找的是一个至少向服务器发送一个没有错误/警告的文件的示例.如果uploadadapter可以是scraped,并且可以使用CKfinder之外的其他东西,那就好了.目前,我想问题最有可能出现在Vue组件中.

推荐答案

使用extraPlugins而不是extraPlugin.

Vue.js相关问答推荐

如何使用 vueJS 上的 ref( ) 函数创建二维数组定义?

Vuetify右侧并排switch

无法在cPanel/SSH上构建 | Laravel + Vue优化

Vuetify 复选框未正确显示值

在 Vue 中更改 json 数据后,如何在屏幕上重新呈现表格组件?

将初始值设置为可直接在 HTML 中使用的 vue.js 模型

如何使用 vue 或 javascript 向服务器发送密码?

Vue.js 和观察者模式

Laravel Vue - 如何让 vue 在公共文件夹中查找图像

apache上的Vue-router,子目录下的SPA,只能通过重定向访问页面

导入没有 .vue 扩展名的 *.vue 文件时出现以下错误?

Vue 和 TypeScript 所需的props

使用 VueJS 在 v-for 中转换

带有子菜单的 Vuetify 导航抽屉

Vue Prop 没有初始化器,也没有在构造函数中明确赋值

样式化 Vue 插槽

如何在 vuejs 中的基于类的组件中编写计算设置器

在 Vuejs 中全局导入 Axios 方法

隐藏特定标题及其在 vuetify 数据表中的对应列

Mapbox 事件监听器