quill-image-drop-module 实现富文本内调整图片大小,去掉放缩时的对齐方式设置。

一、Quill 基本使用

1. 帮助文档

vue-quill-editor自定义工具栏,确定光标位置、插入内容,获取选中的内容。

二、图片可拖拽

1. 效果图

在这里插入图片描述

2. 使用

1)下载安装

yarn add vue-quill-editor
yarn add quill
yarn add quill-image-resize-module

2)导入使用

<template>
  <div>
      <quill-editor v-model="content" :options="editorOption" ref="QuillEditor"></quill-editor>
  </div>
</template>

<script>

import { quillEditor, Quill } from 'vue-quill-editor'
import ImageResize from 'quill-image-resize-module' //调整图片大小
Quill.register('modules/imageResize', ImageResize)
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

export default {
  components: {
    quillEditor,
  },
  data() {
    return {
      content: '',
      editorOption: {
        placeholder: '',
        quill: '',
        modules: {
          imageResize: { // 调整图片大小配置
            displayStyles: {
              backgroundColor: 'black',
              border: 'none', // 是否加边框
              color: 'white' // 拖拽时,图片右下角尺寸文字颜色
            },
            modules: ['Resize', 'DisplaySize', 'Toolbar'] // 工具包:允许拖拽、显示尺寸、对齐方式
          },
          toolbar: [ // 工具栏配置
            ['bold', 'italic', 'underline', 'strike'],          //加粗,斜体,下划线,删除线
            [{ 'size': ['small', false, 'large', 'huge'] }],    // 字体大小
            [{ 'header': [1, 2, 3, 4, 5, 6, false] }],          //几级标题
            [{ 'color': [] }, { 'background': [] }],            // 字体颜色,字体背景颜色
            [{ 'align': [] }],                                  //对齐方式
            [{ 'indent': '-1' }, { 'indent': '+1' }],           // 缩进
            [{ 'list': 'ordered' }, { 'list': 'bullet' }],      //列表
            [{ 'script': 'sub' }, { 'script': 'super' }],       // 上下标
            ['blockquote', 'code-block'],                       //引用,代码块
            ['clean'],                                          //清除字体样式
            ['image', 'video']                                  //上传图片、上传视频
          ]
        }
      }
    }
  }
</script>

3. 安装中遇到的问题

在这里插入图片描述

  • 解决方法:
    在 vue.config.js 中添加如下代码。
const webpack = require('webpack')

const config = {
  configureWebpack:{
    plugins: [
        new webpack.ProvidePlugin({
            'window.Quill': 'quill/dist/quill.js',
            'Quill': 'quill/dist/quill.js'
        }),
    ]
  }
    
};

module.exports = config;

三、取消拖拽时,图片的对齐方式

解决方法:imageResize 配置中的 modules,去掉 Toolbar。

imageResize: {
 displayStyles: {
  backgroundColor: 'pink',
  border: 'none',
  color: 'orange' // 拖拽时,图片右下角尺寸文字颜色
 },
 modules: ['Resize', 'DisplaySize'] // 工具包:允许拖拽、显示尺寸、对齐方式
},
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue CLI中使用Quill-image-resize-module,请按照以下步骤操作: 1. 安装QuillQuill-image-resize-module 打开终端并运行以下命令: ``` npm install quill quill-image-resize-module --save ``` 2. 在Vue组件中导入QuillQuill-image-resize-module 在Vue组件的`<script>`标签中导入QuillQuill-image-resize-module: ```javascript import Quill from 'quill' import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css' import 'quill/dist/quill.bubble.css' import ImageResize from 'quill-image-resize-module' ``` 3. 在Vue组件中注册Quill-image-resize-module 在Vue组件的`<script>`标签中注册Quill-image-resize-module: ```javascript Quill.register('modules/imageResize', ImageResize) ``` 4. 在Vue组件的模板中使用Quill 在Vue组件的模板中使用Quill,并添加`imageResize`模块: ```html <template> <div id="editor"> <quill-editor :options="editorOptions" v-model="content"></quill-editor> </div> </template> <script> import Quill from 'quill' import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css' import 'quill/dist/quill.bubble.css' import ImageResize from 'quill-image-resize-module' import { QuillEditor } from 'vue-quill-editor' Quill.register('modules/imageResize', ImageResize) export default { components: { QuillEditor, }, data() { return { content: '', editorOptions: { modules: { toolbar: [['bold', 'italic', 'underline', 'strike'], ['image']], imageResize: {}, }, }, } }, } </script> ``` 现在,您可以使用Quill-image-resize-module在Vue CLI中调整图像大小了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值