Vue3使用vue-quill富文本 图片缩放、拖拽功能

先看效果图

安装下面几个插件

富文本

npm install @vueup/vue-quill --save

图片拖拽 

npm install quill-image-drop-module --save

图片缩放

npm install quill-blot-formatter --save

Quill注册插件  ImageDrop、BlotFormatter

import '@vueup/vue-quill/dist/vue-quill.snow.css'
import { QuillEditor, Quill } from '@vueup/vue-quill'

import { ImageDrop } from 'quill-image-drop-module'
Quill.register('modules/imageDrop', ImageDrop)

import BlotFormatter from 'quill-blot-formatter'
Quill.register('modules/blotFormatter', BlotFormatter)

完整代码

<template>
  <QuillEditor
    ref="editorRef"
    contentType="html"
    v-model:content="content"
    :options="editorOption"
    style="height: 300px; width: 100%"
  />
</template>

<script lang="ts">
import '@vueup/vue-quill/dist/vue-quill.snow.css'
import { QuillEditor, Quill } from '@vueup/vue-quill'

import { ImageDrop } from 'quill-image-drop-module'
Quill.register('modules/imageDrop', ImageDrop)
import BlotFormatter from 'quill-blot-formatter'
Quill.register('modules/blotFormatter', BlotFormatter)

import { defineComponent, reactive, toRefs } from 'vue'

export default defineComponent({
  components: { QuillEditor },
  setup() {
    const state = reactive({
      content: ``,
      // 富文本编辑器配置
      editorOption: {
        modules: {
          // 工具栏
          toolbar: [
            [{ header: [1, 2, 3, 4, 5, 6] }], // 标题
            [{ size: ['small', false, 'large', 'huge'] }], // 字体大小
            ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
            ['blockquote', 'code-block'], // 引用  代码块
            [{ header: 1 }, { header: 2 }], // 1、2 级标题
            [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
            [{ script: 'sub' }, { script: 'super' }], // 上标/下标
            [{ indent: '-1' }, { indent: '+1' }], // 缩进
            [{ direction: 'rtl' }], // 文本方向
            [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
            [{ font: ['songti'] }], // 字体种类
            [{ align: [] }], // 对齐方式
            ['clean'], // 清除字体样式
            ['image', 'link', 'video'] // 图片、链接、视频
          ],
          // 图片拖拽
          imageDrop: true,
          // 图片缩放
          blotFormatter: {
            // overlay: {
            //    style: {
            //        border: '2px solid red',
            //    }
            // },
            toolbar: {
              mainClassName: 'blot-formatter__toolbar'
            }
          }
        },
        // 主题
        theme: 'snow', // snow: 有工具栏  bubble:只有文本域的
        placeholder: '请输入内容',
        // 是否只读
        readyOnly: false
      }
    })

    return {
      ...toRefs(state)
    }
  }
})
</script>

如有错误,欢迎随时雅正。

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
Vue Quill Editor是一个Vue富文本编辑器插件,它可以用于在Vue项目中进行富文本编辑。您可以通过安装Vue-Quill-Editor和Quill使用它。 关于图片预览的问题,根据提供的引用内容,我没有找到直接关于富文本图片预览的说明。但是,根据Vue Quill Editor的使用方法,您可以使用自定义的toolbar来实现相关功能。您可以在toolbar中添加一个按钮,当用户点击该按钮时,触发一个方法来预览富文本中的图片。您可以使用Vue的v-if指令根据条件来显示或隐藏图片预览的组件。具体实现的代码如下所示: ``` <template> <div class="editor"> ... <!-- 自定义toolbar中增加图片预览按钮 --> <div id="my-toolbar"> ... <button @click="previewImages">预览图片</button> </div> ... </div> </template> <script setup> import { QuillEditor, Quill } from '@vueup/vue-quill' import { getCurrentInstance, ref } from "vue"; const { proxy } = getCurrentInstance(); const previewImages = () => { // 实现预览图片的逻辑 // 可以使用Quill的API获取富文本中的图片,然后展示在预览组件中 } </script> ``` 在上述代码中,您可以在`previewImages`方法中实现预览图片的逻辑。您可以使用Quill的API获取富文本中的图片,并将其显示在预览组件中。 需要注意的是,具体的图片预览逻辑和组件实现取决于您的具体需求和项目实现。您可以根据自己的情况进行适当的调整和扩展。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue-Quill-Editor富文本编辑器的使用教程](https://download.csdn.net/download/weixin_38701952/13980065)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [使用vue-quill展示富文本内容](https://blog.csdn.net/qq_36576430/article/details/127793120)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值