VueJS CKeditor5上传图片

2024-03-24

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

第一次尝试过简单上传适配器 https://ckeditor.com/docs/ckeditor5/latest/features/image-upload/simple-upload-adapter.html这给了我以下错误:

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

我尝试制作一个上传适配器。作为上传适配器,我采取了example https://ckeditor.com/docs/ckeditor5/latest/framework/guides/deep-dive/upload-adapter.html并修改了网址。 uploadadapter.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>

但是,每次尝试上传文件时,都会返回以下警告:

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

已查看网址,但它只是让我绕圈,因此没有任何进展。我正在寻找的是一个至少将文件发送到服务器而没有错误/警告的示例。如果上传适配器可以scraped除了 CKfinder 之外,其他东西也可以使用。目前我猜问题最有可能出在Vue组件上。


use extraPlugins代替extraPlugin.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

VueJS CKeditor5上传图片 的相关文章

  • Konvajs/Vue-Konva 使用连接器动态连接形状

    我在用Konvajs Vue Konva在我的内Vuejs Nuxt应用 使用Konva我正在创建Rect在运行时动态形状 现在我想用某种Connectors连接不同的Rect Shapes这样我就可以得到其逻辑source Rect哪个是
  • 组件可以知道 vue-router 中的子路由吗

  • 如何在Vue.js中添加一堆全局过滤器?

    我想在 Vue js 应用程序中使用一些全局过滤器 我知道我需要在主 Vue 实例之前定义它们 但从代码组织的角度来看 将它们全部放在 main js 文件中对我来说似乎并不正确 我怎样才能将定义放在一个单独的文件中 导入到 main js
  • Vue.js:条件类样式绑定

    我有一些数据可以通过以下方式访问 content term goes here 这评估为true or false 我想根据表达式的真实性添加一个类 如下所示 i class fa i where true给我上课fa checkbox m
  • 如何在CKEditor 4中设置默认字体和字体大小

    我使用以下代码在 CKEditor 4 中设置默认字体和字体大小 config font defaultLabel Tahoma config fontSize defaultLabel 24px 但上面的代码在 Mozilla Firef
  • 在Vuex模块中进行继承的方法

    我使用 VueJS 和 Vuex 构建我的应用程序 当我有多个模块使用相同的数据字段时 我遇到了这个问题 它是关于像 dat 这样的 API 配置 getUsers state commit axios get urls API USER
  • 您没有浏览服务器的权限?

    我将 kcfinder 与 ckeditor 一起使用 改变的同时disabled to false在 kcfinder 的配置文件中没有问题 但是用以下命令覆盖它 SESSION KCFINDER array disabled gt fa
  • 如何将 primevue css 文件添加到 JHipster 项目

    我正在尝试使用 vue js 应用程序将 primevue 添加到我的 jhister 中 我正在遵循这些步骤 1 运行这些评论 npm install primevue save npm install primeicons save 2
  • 从 vueJS 方法调用 setTimeout() 不起作用

    我试图允许用户从应用程序重置或关闭给定服务器 我现在正在开发界面 并希望向用户提供有关正在发生的事情的消息 我显示数据对象中定义的消息来指示所采取的操作 我使用 setTimeout 来切换重置 消息和重置消息 请参阅以下方法 system
  • 未找到 CSS 和 JS 的 Vue dist 路径

    我在构建后渲染 VueJS 应用程序时遇到问题 当我查看构建文件夹并检查路径时 我的资产 css 和 javascript 的路径开头有一个正斜杠 这使得我的 css 资源和 javascript 无法找到 我想知道在运行构建脚本之前如何避
  • Laravel 未定义

    好吧 我正在使用新的 laravel 5 3 和 vue js 我想对数据库中的一些用户进行 GET 调用 顺便说一句 我正在使用组件 这是我的 app js require bootstrap Vue component example
  • axios get 带有标头授权的请求在 Edge 浏览器上不起作用

    我在 vuejs 应用程序中使用带有标头的 axios get 请求 在 Chrome 和 Firefox 中工作正常并得到响应 但在边缘它不起作用 出现网络错误 我正在发送带有标题授权的请求 axios get url headers A
  • vue 组件中的 Csrf 令牌

    我有集成了 Vue js 的 Laravel 5 3 项目 我想使用CSRF TOKEN以我的形式 表单html代码在Vue组件文件中 resources assets js bootstrap js 我有这个 Vue http inter
  • 完全丢失:Django Rest Framework 中的序列化器和更新的多对多

    我已经研究这个问题几个小时了 但没有找到解决方案 我只是不明白 我有一个有很多孩子的父母 我创建了一个视图 允许我获取父级的所有子级 现在我想结束该列表 并使用新的子列表对父列表进行 PATCH 我明白我需要写一个自定义update方法 但
  • Vue 绑定到外部对象

    我正在尝试使用 Vue 作为一个非常薄的层来将现有模型对象绑定到视图 下面是一个玩具应用程序 说明了我的问题 我有一个GainNode https developer mozilla org en US docs Web API GainN
  • VueJS/浏览器缓存生产版本

    我有一个 VueJS 应用程序 每当我跑步时npm run build它创建了一组新的dist 文件 但是 当我将它们加载到服务器上 删除旧版本后 并在浏览器中打开页面时 它会加载旧版本 我假设从缓存 当我刷新页面时 它加载新代码没有问题
  • 停止接收来自被破坏的子组件的事件

    我有一个父级 我可以在其中动态添加子组件 当在挂载中添加子组件时 我为事件注册一个侦听器 EventBus on content type saving function logic here 问题是 当通过从子组件数组中删除该组件而在父组
  • CKEditor 5 保存选定的文本并在恢复内容后将其再次设置为选定

    我一直在使用 CKEditor 5 var mySelection editor getSelection 例如 获取选定的文本并能够将其保存到数据库中 我想知道是否有一种更简单的方法将所选文本保存到数据库 然后在恢复文本后将其设置为在编辑
  • 在Vue.js中,如何选择组件的节点元素? $refs 可能吗?

    因为我想选择组件的节点元素 所以我想也许我可以使用 refs Parent
  • Laravel Passport 中间件保护路由“未经身份验证”问题

    我使用 Laravel Passport 进行身份验证 因此我将路由置于中间件保护中 UPDATED 为了清楚起见 我也添加了 UsersController public function getUser users Auth user

随机推荐

  • 为什么人们不访问 Rspec 中的数据库?

    我经常看到Rspec中使用mock的代码 如下所示 describe GET show do it should find and assign question do question Question new Question shou
  • 如何配置 Nginx 以使用 html5 模式

    对于 angularjs 中的干净网址 我必须使用 locationProvider html5Mode true 但是当我刷新页面时 它显示 404 我读到我需要配置服务器文件 结构 html views home html about
  • Spark DataFrame:对组进行操作

    我有一个正在操作的 DataFrame 我想按一组列进行分组 并按组对其余列进行操作 正常情况下RDD land 我认为它看起来像这样 rdd map tup gt tup 1 tup 2 tup 3 tup groupByKey forE
  • document.getElementById 对于单标签 DIV 失败

    我的 HTML 页面上有 2 个 DIV div div div div 我有一个脚本可以访问网络服务并用数据填充它们 document getElementById divDebug innerHtml rawResult documen
  • 最低限度的文本清理

    在接受 存储 处理和显示 Unicode 文本的应用程序中 为了讨论的目的 我们假设它是一个 Web 应用程序 哪些字符应该always从传入文本中删除 我能想到一些 大部分列在C0 和 C1 控制代码维基百科文章 http en wiki
  • 从命令行执行Java

    我的桌面上有一个名为 Stuff 的文件夹 在该文件夹中我有以下内容 你好 java mail jar 而Hello java是从mail jar导入的 所以我需要告诉Hello java寻找mail jar 从 Windows 命令行和
  • 仅使用 Dockerfile 中的其他更改重建相同的 docker 映像

    我使用 Dockerfile 构建 Docker 映像 构建镜像后 我对 Dockerfile 进行了一些基本更改 是否可以仅通过额外的更改来重建相同的映像 由于创建图像需要很长时间 因此我不想完全构建它 提前致谢 所有 docker 构建
  • 设置私有 luarocks 存储库

    对于我的设置 我需要一个 luarocks rock 的私有存储库 我可以将它们安装在我的开发环境中 而无需连接到互联网 为 luarocks 设置远程存储库的步骤是什么 我可以使用 sftp 服务器吗 有人有过这样的经历吗 在深入研究这个
  • C++:类成员引用有效性?

    Class A A int foo m foo foo int m foo int main void A bar 0 int var 5 bar new A var std cout lt lt Is m foo still valid
  • Python中按多个条件排序

    我正在使用Python 3 8 我试图按分数对玩家进行排序 按降序排列 然后 只有当他们具有相同的分数时 才按排名排序 我已经读过排序方法 https docs python org 3 8 howto sorting html Pytho
  • 从其他服务器下载之前是否可以动态压缩文件?

    我想知道是否可以编写浏览器扩展或简单的 Java 脚本代码 其中包含指向不同位置的 URL 列表 可以将所有内容压缩在一起 我是说 例如 有 3 个不同的图像文件 http example1 com a png http example1
  • D3 在将 .data() 设置为附加元素时抛出“无法读取 null 的属性‘ownerDocument’”

    我收到此错误 未捕获的类型错误 无法读取 null 的属性 ownerDocument 这是来自设置的行 data 到最近附加的元素d3 const someSet someSelection filter some filter some
  • ios 延迟位置更新的问题

    过去两天我一直在尝试在应用程序中实现延迟位置更新 我面临的问题是 void locationManager CLLocationManager manager didUpdateLocations NSArray locations 即使在
  • 如何编写使用 Django 模块的独立 Python 脚本?

    在 PyCharm 中 我创建了一个空白的新 Django 应用程序 创建了一些模型并发布manage py makemigrations and manage py migrate 我尝试编写一个独立的脚本 用初始数据填充数据库 在其导入
  • keras mnist.load_data() 速度超慢,一段时间后会抛出错误

    这是我使用的完整代码 import os import numpy as np import matplotlib pyplot as plt from tqdm import tqdm from keras layers import I
  • 在 Windows 上更改 apache 的文档根不起作用

    我正在尝试更改本地 Windows 计算机上的 documentroot 以指向 htdocs 下面的子目录 我已经更改了 httpd conf 中的 DocumentRoot 位置以及目录位置 我已经重新启动了 Apache 但用 PHP
  • 为什么十六进制数会自动转换为十进制数?

    我正在开发一个Python小方法 它需要从另一个文件中读取代表键和值的字典 但我似乎遇到了我发送的数值表示的问题 例如 我的字典中的某些键如下所示 id dict val a 0x0000 val b 0x1000 但我注意到 当我尝试遍历
  • 如果目录不存在则创建

    我正在编写一个 PowerShell 脚本来创建多个目录 如果它们不存在 文件系统看起来与此类似 D D TopDirec SubDirec Project1 Revision1 Reports D TopDirec SubDirec Pr
  • @GenerateValue 和 @GenericGenerator 之间的区别

    有时我发现他们在一起 有时单独 其他时候他们似乎也做同样的事情 有什么不同 以下是三个例子 他们的做法有何不同 为什么我不能对所有这些都使用 GenerateValue 实施例1 Id GeneratedValue generator in
  • VueJS CKeditor5上传图片

    在 Vuejs 中使用 CKeditor5 上传图像时遇到问题 第一次尝试过简单上传适配器 https ckeditor com docs ckeditor5 latest features image upload simple uplo