Vue2-Editor 使用

本文详细介绍了如何在Vue项目中使用Vue-Editor组件,包括安装、配置、自定义工具栏及处理图像上传等功能,并提供了兼容性解决方案。

Vue-Editor底层采取的是quill.js,而quill.js采用的是html5的新属性classList,所以版本低于ie10会报错“无法获取未定义或 null 引用的属性‘confirm’”,而作者写该组件时似乎把ie10也舍弃了,直接支持ie11+,因此需要兼容ie9,ie10的建议更换编辑器。


1.安装

npm install --save vue2-editor

 

2.在需要用得组件里面引入

import { VueEditor } from 'vue2-editor'
components:{
    VueEditor
} 

 

3.使用

<template>
    <div v-loading="loading"><!--上传图片时得加载画面-->
      <VueEditor style="width: 80%"<!--宽度-->
        useCustomImageHandler<!--处理图像上传,而不是使用默认转换为Base64 默认图片为base64路径 加上此属性后显示为正常路径-->
        @imageAdded="handleImageAdded"<!--上传图片函数-->
        :editorToolbar="customToolbar"<!--自定义工具栏-->
        v-model="content"></VueEditor>
    </div>
</template>
<script>
    export default {
        data(){ 
            return{
                content:'',
                loading:false,
                customToolbar::[
                    ['bold', 'italic', 'underline'],
                    [{'align':''},{'align':'center'},{'align':'right'}],
                    [{ 'list': 'ordered'}, { 'list': 'bullet' }, { 'list': 'check' }],
                    [{'background':[]},{'color':[]}],
                    ['image','link'],
                    ['strike'],
                    ['clean'],
                    ],//更多工具栏选项在下面
                }
        }
        methods:{
        handleImageAdded:function(file,Editor,cursorLocation){
            //上传图片操作

            //把获取到的图片url 插入到鼠标所在位置 回显图片
            Editor.insertEmbed(cursorLocation, 'image', url);
        }
        }
    }
</script>

 

4.工具栏选项

* align:{”,’center’,’right’} 文本对齐方式 
* background 背景色 
* blockquote 引用 
* bold 加粗 
* clean 清楚格式 
* code 代码 
* code-block 代码块 
* color 字体颜色 
* direction:{”,’rtl’} 方向 
* float:{‘center’,’full’,’left’,’right’} 浮动 
* formula 公式 
* header 标题 
* italic 斜体 
* image 图片 
* indent 缩进 
* link 链接 
* list :{‘ordered’,’bullet’,’check’} 列表 有序 多选列别 
* script :{‘sub’,’super’} 脚本 
* strike 作废 
* underline 下划线 
* video 视频 

 

参考文档:

    https://www.vue2editor.com/examples/#how-to-use-custom-quill-modules

    https://www.npmjs.com/package/vue2-editor

转载于:https://www.cnblogs.com/xiaoyaoxingchen/p/10767203.html

参考的引用内容中未提及vue2-editor样式设置、定制及相关案例的具体信息。不过可以从一般的Vue组件样式设置思路来推测vue2-editor的样式相关操作。 在Vue中,对于组件的样式设置通常有以下几种方式: 1. **全局样式**:在项目的全局样式文件(如`styles.css` 或 `styles.scss`)中添加样式规则,这些规则会应用到整个项目中的vue2-editor组件。例如: ```css .vue-editor { border: 1px solid #ccc; padding: 10px; } ``` 2. **局部样式**:在组件的`<style>`标签中添加样式,使用`scoped`属性确保样式只作用于当前组件。 ```vue <template> <vue-editor v-model="contentTest" class="media"></vue-editor> </template> <style scoped> .media { background-color: #f9f9f9; } </style> ``` 3. **自定义类名**:可以通过给vue2-editor组件添加自定义类名,然后在样式文件中针对该类名编写样式。 ```vue <template> <vue-editor v-model="contentTest" class="custom-editor"></vue-editor> </template> <style> .custom-editor { font-family: Arial, sans-serif; } </style> ``` 对于定制vue2-editor的样式,需要深入了解该组件的结构和类名。可以通过浏览器的开发者工具查看组件的DOM结构,找到对应的类名进行样式修改。 关于相关案例,由于没有具体的引用信息,以下是一个简单的示例,展示如何通过自定义样式来改变vue2-editor的外观: ```vue <template> <div> <vue-editor v-model="contentTest" class="custom-editor"></vue-editor> <div class="mediaContent" v-html="contentTest"></div> </div> </template> <script> export default { data() { return { contentTest: '' }; } }; </script> <style> .custom-editor { border: 2px solid #007BFF; border-radius: 5px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); padding: 15px; } </style> ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值