vue quill使用&quill 自定义图片上传&自定义mp4 更换标签
pluins 创建quill 目录
创建文件video.js
import { Quill } from 'vue-quill-editor'
// 源码中是import直接倒入,这里要用Quill.import引入
const BlockEmbed = Quill.import('blots/block/embed')
const Link = Quill.import('formats/link')
const ATTRIBUTES = ['height', 'width']
class Video extends BlockEmbed {
static create (value) {
const node = super.create(value)
// 添加video标签所需的属性
node.setAttribute('controls', 'controls')
node.setAttribute('type', 'video/mp4')
node.setAttribute('src', this.sanitize(value))
return node
}
static formats (domNode) {
return ATTRIBUTES.reduce((formats, attribute) => {
if (domNode.hasAttribute(attribute)) {
formats[attribute] = domNode.getAttribute(attribute)
}
return formats
}, {})
}
static sanitize (url) {
return Link.sanitize(url) // eslint-disable-line import/no-named-as-default-member
}
static value (domNode) {
return domNode.getAttribute('src')
}
format (name, value) {
if (ATTRIBUTES.indexOf(name) > -1) {
if (value) {
this.domNode.setAttribute(name, value)
} else {
this.domNode.removeAttribute(name)
}
} else {
super.format(name, value)
}
}
html () {
const { video } = this.value()
return `<a href="${video}">${video}</a>`
}
}
Video.blotName = 'video' // 这里不用改,楼主不用iframe,直接替换掉原来,如果需要也可以保留原来的,这里用个新的blot
Video.className = 'ql-video'
Video.tagName = 'video' // 用video标签替换iframe
export default Video
模版中引用注册
//import { quillEditor } from "vue-quill-editor";
//import { ImgHandlers, ToolbarOptions } from "../../api/upload";
// //这里引入修改过的video模块并注册
// import Video from '../../plugins/quill/video'
// Quill.register(Video, true)
// import Audio from '../../plugins/quill/audio'
// Quill.register(Audio, true)
api/upload 配置
import {
baseUrl
} from './env'
// 工具栏配置
const ToolbarOptions = [
["bold", "italic", "underline", "strike"], // toggled buttons
["blockquote", "code-block"],
// [{ header: 1 }, { header: 2 }], // custom button values
[{ list: "ordered" }, { list: "bullet" }],
// [{ script: "sub" }, { script: "super" }], // superscript/subscript
[{ indent: "-1" }, { indent: "+1" }], // outdent/indent
[{ direction: "rtl" }], // text direction
[{ size: ["small", false, "large", "huge"] }], // custom dropdown
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ color: [] }, { background: [] }], // dropdown with defaults from theme
[{ font: [] }],
[{ align: [] }],
["link", "image","audio", "video"],
// ["clean"] // remove formatting button
];
// 图片上传参数配置
const uploadConfig = {
action: baseUrl + "/common/uploadImg", // 必填参数 图片上传地址
methods: "POST", // 必填参数 图片上传方式
//token: "229d6e933a679f40030d03f1e5c4a4ff", // 可选参数 如果需要token验证,假设你的token有存放在sessionStorage
name: "file_name", // 必填参数 文件的参数名
size: 500, // 可选参数 图片大小,单位为Kb, 1M = 1024Kb
accept: "image/png, image/gif, image/jpeg, image/bmp, image/x-icon" // 可选 可上传的图片格式
};
// handler重写事件, 任何工具按钮的功能都可以重写,这里只重写图片上传事件
const ImgHandlers = {
image: function image() {
var self = this;
var fileInput = this.container.querySelector("input.ql-image[type=file]");
if (fileInput === null) {
fileInput = document.createElement("input");
fileInput.setAttribute("type", "file");
// 设置图片参数名
if (uploadConfig.name) {
fileInput.setAttribute("name", uploadConfig.name);
}
// 可设置上传图片的格式
fileInput.setAttribute("accept", uploadConfig.accept);
fileInput.classList.add("ql-image");
// 监听选择文件
fileInput.addEventListener("change", function() {
// 如果图片限制大小
if (
uploadConfig.size &&
fileInput.files[0].size >= uploadConfig.size * 1024
) {
fileInput.value = "";
return;
}
// 创建formData
var formData = new FormData();
formData.append(uploadConfig.name, fileInput.files[0]);
// 如果需要token且存在token
if (uploadConfig.token) {
formData.append("token", uploadConfig.token);
}
// 图片上传
var xhr = new XMLHttpRequest();
xhr.open(uploadConfig.methods, uploadConfig.action, true);
// 上传数据成功,会触发
xhr.onload = function(e) {
if (xhr.status === 200) {
var res = JSON.parse(xhr.responseText);
//console.log(res)
let length = self.quill.getSelection(true).index;
self.quill.insertEmbed(length, "image", res.data.url);
self.quill.setSelection(length + 1);
}
fileInput.value = "";
};
// 开始上传数据
xhr.upload.onloadstart = function(e) {
fileInput.value = "";
// console.log('开始上传')
};
// 当发生网络异常的时候会触发,如果上传数据的过程还未结束
xhr.upload.onerror = function(e) {};
// 上传数据完成(成功或者失败)时会触发
xhr.upload.onloadend = function(e) {
// console.log('上传结束')
};
xhr.send(formData);
});
this.container.appendChild(fileInput);
}
fileInput.click();
}
};
export {uploadConfig,ImgHandlers,ToolbarOptions}
模版初始化
export default:
components:{quillEditor}
// computed: {
// editor() {
// return this.$refs.myQuillEditor.quill;
// },
// editor2() {
// return this.$refs.myQuillEditor2.quill;
// },
// }, data return
// editorOption: {
// placeholder: "请输入文本信息...",
// modules: {
// toolbar: {
// container: ToolbarOptions, // 工具栏
// handlers: ImgHandlers
// }
// }
// }, methods:
// //初始化编辑器
// onEditorReady(editor) {
// //console.log(editor);
// },
// onEditorReady2(editor2) {}, template: <div class="edit_container">
<quill-editor
v-model="questionForm.questionOptions"
ref="myQuillEditor2"
class="editer"
:options="editorOption"
@ready="onEditorReady2($event)"
></quill-editor>
</div>
webpack.base.conf.js
externals: {
'vue': 'Vue',
'vue-router': 'VueRouter',
'element-ui': 'ELEMENT',
// 'vue-quill-editor': 'VueQuillEditor',
'echarts': 'echarts',
},
index.html
<!-- Include the Quill library -->
<!-- <script src="//cdn.bootcss.com/quill/1.3.4/quill.js"></script> -->
<!-- <script src="//cdn.jsdelivr.net/npm/vue"></script> -->
<!-- Quill JS Vue -->
<!-- <script src="//cdn.jsdelivr.net/npm/vue-quill-editor@3.0.4/dist/vue-quill-editor.js"></script>
<script src="//cdn.jsdelivr.net/npm/quill-image-resize-module"></script> --> <!-- Include stylesheet -->
<!-- <link href="//cdn.bootcss.com/quill/1.3.4/quill.core.css" rel="stylesheet">
<link href="//cdn.bootcss.com/quill/1.3.4/quill.snow.css" rel="stylesheet">
<link href="//cdn.bootcss.com/quill/1.3.4/quill.bubble.css" rel="stylesheet"> -->
vue quill使用&quill 自定义图片上传&自定义mp4 更换标签的更多相关文章
- vue项目富文本编辑器vue-quill-editor之自定义图片上传
使用富文本编辑器的第一步肯定是先安装依赖 npm i vue-quill-editor 1.如果按照官网富文本编辑器中的图片上传是将图片转为base64格式的,如果需要上传图片到自己的服务器,需要修改 ...
- CKEditor5 + vue2.0 自定义图片上传、highlight、字体等用法
因业务需求,要在 vue2.0 的项目里使用富文本编辑器,经过调研多个编辑器,CKEditor5 支持 vue,遂采用.因 CKEditor5 文档比较少,此处记录下引用和一些基本用法. CKEdit ...
- ueditor 百度编辑器 自定义图片上传路径和格式化上传文件名
今天项目中需要自定义图片上传的保存路径,并且不需要按照日期自动创建存储文件夹和文件名,我的ueditor版本是1.3.6.下面记录一下我配置成功的方法,如果有什么不对的地方欢迎指出,共同学习: 1:我 ...
- rails使用bootstrap3-wysiwyg可视化编辑器并实现自定义图片上传插入功能
之前在rails开发中使用了ckeditor作为可视化编辑器,不过感觉ckeditor过于庞大,有很多不需要的功能,而且图片上传功能不好控制不同用户可以互相删除图片,感觉很不好.于是考虑更改可视化编辑 ...
- 使用百度UMeditor富文本编辑器,修改自定义图片上传,修改源码
富文本编辑器,不多说了,这个大家应该都用到过,至于用到的什么版本,那就分很多种 CKEditor:很早以前叫FCK,那个时候也用过,现在改名了,比较流行的一个插件,国外很多公司在用 UEDITOR:百 ...
- Jquery自定义图片上传插件
1 概述 编写后台网站程序大多数用到文件上传,可是传统的文件上传控件不是外观不够优雅,就是性能不太好看,翻阅众多文件上传控件的文章,发现可以这样去定义一个文件上传控件,实现的文件上传的效果图如下: 2 ...
- vue+axios实现移动端图片上传
在利用vue做一些H5页面时,或多或少会遇到有图片上传的操作,主要是运用html5里面的input[type=file]来实现,传递到后端的数据是以二进制的格式传递,所以上传图片的请求与普通的请求稍微 ...
- jeecg uedit 自定义图片上传路径
jeecg uedit 图片上传配置自定义物理路径,简单描述:我们知道 jeecg 中使用的 uedit 默认图片上传路径为 "当前项目\plug-in\ueditor\jsp\upload ...
- vue“欺骗”ueditor,实现图片上传
一.环境介绍 @vue/cli 4.3.1 webpack 4.43.0 ueditor1.4.3.3 jsp版 二.springboot集成ueditor,实现分布式图片上传 参考我的另一篇博客,& ...
随机推荐
- 剪切板工具:Ditto
DittoClipboard manager; 剪贴板工具https://ditto-cp.sourceforge.io/ 参考资料 https://www.liutf.com/posts/37207 ...
- 过滤器( filter )的使用
转自:https://www.jianshu.com/p/2ea2b0e4d1f2 过滤器通常 在 web 服务端用的比较多,有要功能 在客户端的请求访问后端资源之前,拦截这些请求. 在服务器的响应发 ...
- mysql 添加大量测试数据
mysql 添加大量测试数据 场景 针对于大量测试数据插入,检测sql执行速度 第一步:建表 // 测试表 CREATE TABLE user ( id int(11) NOT NULL AUTO_I ...
- Java基础笔试练习(六)
1.在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数个数.类型或顺序各不相同,传回的值也可以不相同.这种面向对象程序的特性称为? A.隐藏 B.覆盖 C.重载 D.Java不支持此特性 ...
- MATLAB 求一个点周围 voronoi 边的顶点的坐标
本代码在[MATLAB 2015b] 下编写运行成功,不保证所有版本适用. x=[0 -.5 1 1 -1]; y=[0 -1 -.5 1 1]; voronoi(x,y);axis([-2 2 -2 ...
- Python字符串图解
>>> word = "Python" >>> word[:2] # character from the beginning to posi ...
- oracle笔记之计算年龄、工龄和TRUNC
方法一:利用months_between 函数计算 SELECT TRUNC(months_between(sysdate, birthday)/12) AS agefrom dual; 方法二:日期 ...
- shell 学习笔记4-shell内置变量命令
一.shell 的一些内置命令 常用的一内部命令有:echo.eval.exec.export.read.shift 1.echo命令-在屏幕中输出信息 1)说明 格式:echo args #< ...
- 什么是RAID(磁盘阵列)
RAID全称Redundant Array of Independent Disk,即独立冗余磁盘阵列.RAID技术由加州大学伯克利分校1987年提出,最初是为了组合小的廉价磁盘来代替大的昂贵磁盘,同 ...
- Python之原始数据-1
一.数据对于模型来说是基础,是数据成就了模型,而现在的又是一个数据时代,比如:淘宝等.通过对用户数据的分析挖掘,预测用户的消费习惯等,再比如:人工智能.通过提取摄像头的图片帧数,通过分析图片,得出具体 ...